Hi Vinllen, I met the same problem too. I solved it by invoking a hub.sleep method to sleep for several milliseconds. It allowed other threads to continue. And it works. You probably could try it. Best Regards Haixiang YANG Date: Fri, 24 Jul 2015 10:33:53 +0800 From: [email protected] To: [email protected]; [email protected]; [email protected] Subject: Re: [Ryu-devel] How to creat new thread in RYU
Dear iwase : Thankyou, so do you have any other idea to solve this problem. I found this problem could not be solved even when i use epoll which is not a blocking I/O. On Fri, Jul 24, 2015 at 7:51 AM, Yusuke Iwase <[email protected]> wrote: Hi, On 2015年07月23日 17:21, Vinllen Chen wrote: > Hi, Haixiang and iwase : > > Hear comes my code : > class Main(app_manager.RyuApp) : > .... > def __init__(self, *args, **kwargs): > .... > def start(self) : > super(Main, self).start() > self.threads.append(hub.spawn(Tun_Tap())) # call Tun_Tap class > > class Tun_Tap() : > def __init__(self) : > self.create_device() > self.run() > def create_device(self) : # create tun/tap device > self.tun = open('/dev/net/tun', 'r+b') > ifr = struct.pack('16sH', 'tap0', IFF_TAP | IFF_NO_PI) > fcntl.ioctl(self.tun, TUNSETIFF, ifr) > fcntl.ioctl(self.tun, TUNSETOWNER, 1000) > subprocess.check_call('ifconfig tap0 30.1.1.1/24 > <http://30.1.1.1/24>', shell=True) > def run(self) : > while True: > packet_raw = os.read(self.tun.fileno(), 2048) # it will read from > the tun/tap device, but it'll be blocked when there is no data > > The Tun_Tap class will be blocked when run "read", so do you have any idea to > solve this problem ? I find the Main class will never run when the Tun_Tap is > blocked Ryu uses eventlet (Python networking library) to create new threads. In eventlet thread, the codes with blocking I/O (e.g. file I/O) may block all other threads. Thanks, Iwase > > On Thu, Jul 23, 2015 at 4:04 PM, Yusuke Iwase <[email protected] > <mailto:[email protected]>> wrote: > > Hi, > > On 2015年07月23日 16:18, Vinllen Chen wrote: > > Hi, Dear all: > > > > I want to create a new thread/coroutine in RYU app, i find it's not ok > to write the code below: > > > > class App(app_manager.RyuApp) : > > def __init__(self, *args, **kwargs): > > ... > > hub.spawn(New_One()) > > What messages did you get? > > hub.spawn() is defined as follow. > https://github.com/osrg/ryu/blob/master/ryu/lib/hub.py#L47 > > e.g.) > from ryu.lib import hub > ... > class YourApp(app_manager.RyuApp) : > def __init__(self, *args, **kwargs): > ... > hub.spawn(self.target_func) > > def target_func(self): > ... > > Thanks, > Iwase > > > > > -- > > Best Regards, > > Vinllen > > > > > > > ------------------------------------------------------------------------------ > > > > > > > > _______________________________________________ > > Ryu-devel mailing list > > [email protected] <mailto:[email protected]> > > https://lists.sourceforge.net/lists/listinfo/ryu-devel > > > > > > > -- > Best Regards, > Vinllen -- Best Regards,Vinllen ------------------------------------------------------------------------------ _______________________________________________ Ryu-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ryu-devel
------------------------------------------------------------------------------
_______________________________________________ Ryu-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ryu-devel
