can't access internet via ethernet, but i can via WiFi

138

You need to disable wireless network when you connect by Ethernet.

Any OS and Ubuntu has a routing table where rules are set up where to send packets in order to reach Internet or specific network segments.

If your wireless network is enabled, default route is set up to wireless interface and you can't get access to Internet.

General rule is that you can't use more than one network interface in a system without setting up routing.

Share:
138

Related videos on Youtube

colinfang
Author by

colinfang

Updated on September 18, 2022

Comments

  • colinfang
    colinfang over 1 year
    import gevent.monkey
    gevent.monkey.patch_all()
    import gevent
    from queue import Queue
    import random
    import time
    
    
    def getter(q):
        while True:
            print('getting')
            v = q.get()
            print(f'got {v}')
    
    def putter(q):
        while True:
            print(f'start putting')
            v = int(random.random() * 1000)
            # `put_nowait` also seems to yield
            # q.put(v)
            q.put_nowait(v)
            print(f'done putting with {v}')
    
            if random.random() < 0.5:
                print(f'yield')
                time.sleep(0)
    
    
    queue = Queue()
    
    
    gevent.spawn(getter, queue)
    gevent.spawn(putter, queue)
    
    time.sleep(1000)
    

    Doesn't matter if I use queue.put or queue.put_nowait, I saw logs like

    # start putting
    # got 25
    # getting
    # done putting with 535
    

    Does that suggest gevent might do context switch each time it executes queue.put?

    Update

    I modified the code a bit

    flag = True
    
    def getter(q):
        while True:
            print('getting')
            global flag
            flag = False
            v = q.get()
            print(f'got {v}')
    
    def putter(q):
        v = 0
        while True:
            print(f'start putting {v}')
            global flag
            flag = True
            # `put_nowait` also seems to yield
            # q.put(v)
            q.put_nowait(v)
            if not flag:
                raise Exception('yield happened')
    
            print(f'done putting with {v}')
            v += 1
    
            time.sleep(0)
            # If I sleep with non-zero, the above seems to only yield once at the beginning.
            # time.sleep(0.000001)
    
    
    queue = Queue()
    
    
    def myTracer(event, args):
        src, target = args
        if event == "switch":
            # print("from %s switch to %s" % (src, target))
            # Print to stdout like the rest of the code. Otherwise the order of stdout & stderr is not guaranteed.
            traceback.print_stack(file=sys.stdout)
        elif event == "throw":
            print("from %s throw exception to %s" % (src, target))
    
    
    # greenlet.settrace(myTracer)
    
    gevent.spawn(getter, queue)
    putter(queue)
    

    With patched Python Queue,

    • If I sleep(0), it might do context switch.
    • If I sleep(0.0000001), it only yield once at the beginning.
    • If I don't sleep at all, it only yield once at the beginning, and the getter doesn't have a chance to run afterwards.

    Looking at the stack trace, I found Queue.put calls notify, which calls lock.acquire(0). It was then patched so that it calls sleep() in gevent/thread.py

    If I use gevent.queue.Queue instead of Python Queue, it doesn't seem to do context switch.

    • Pilot6
      Pilot6 almost 9 years
      Do you turn of wifi when try to connect by ethernet? And also please edit your question and add output of lspci -knn | grep Eth -A2 terminal command.
    • Pilot6
      Pilot6 almost 9 years
      So do you turn off wireless in Network Manager when you try to connect using Ethernet?
    • equitharn
      equitharn almost 9 years
      Disabling the WiFi and connecting to Ethernet worked! what is the problem in my case?
    • Pilot6
      Pilot6 almost 9 years
      That's not a problem. See my answer.
  • equitharn
    equitharn almost 9 years
    but I've been using internet with lan cable plugged in and wireless network on. When the lan is removed System uses WiFi and when it's reconnected, it uses Ethernet. I've been facing this problem a few days now before that it was all fine
  • Pilot6
    Pilot6 almost 9 years
    That must be because the default route is set up to wireless interface. One interface has a priority. It can be changed, but I do not remember how. Good practice is to disable unneeded interface. It is just a mouse click.
  • Skaperen
    Skaperen almost 9 years
    decide which you want to use then dis- the other one
  • equitharn
    equitharn almost 9 years
    @Skaperen for now I have, but I still need to get WiFi and Ethernet working together, so when I disconnect Ethernet WiFi is connected back again, and vice versa.
  • Nabin
    Nabin about 8 years
    At first I thought it was a joke. :-) Worked like a charm. +1 for it. I just disabled wifi and everything is fine now. Thank you
  • colinfang
    colinfang over 3 years
    If I remove print(f'yield') time.sleep(0) from my code, getter seems never to be triggered, although the settrace shows there are context switchs. Do you know why?