Hi,

On 2017年05月21日 08:01, Yikai Lin wrote:
> Hi all,
> 
> I was trying to launch a GRPC server within an ryu app to talk to my 
> on-switch client. The code for launching the server is as follows:
> 
> server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
> xx_service_pb2_grpc.add_XXServicer_to_server(XXServicer(), server)
> server.add_insecure_port('[::]:50050')
> server.start()
> 
> The server class is minimal with only one function printing out client 
> messages right now
> 
> I tried to put this piece of code in start(), __init__() or even outside the 
> methods, but they all block at server.start(). Normally(such as when running 
> this code in a standalone python app) this piece of code will just finish 
> right away without blocking.

I faced the similar problem when I was implementing my Ryu application before.
First please confirm that your Ryu application return the main thread instance 
if your
application does NOT use OpenFlow features.
Without OpenFlow features in your application, Ryu cannot find the main thread 
(server
or daemon thread) and will determine that there is no thread to wait, then quit
immediately.
To register main thread to Ryu manager, please override "start()" method of 
"RyuApp".

e.g.)

class MyRyuApp(app_manager.RyuApp):

    # Option 1:
    # Override start() method to register "_my_main_loop"
    def start(self):
        super(MyRyuApp, self).start()
        self.threads.append(hub.spawn(self._my_main_loop))

    # Option 2:
    # If your application needs no original main loop,
    # please upgrade RyuApp's event receive loop "self._event_loop"
    # to main loop.
    def start(self):
        return hub.spawn(self._event_loop)


> When blocked, pressing ctrl-c gets me this:
> 
> ^CException in thread Thread-1:
> Traceback (most recent call last):
>   File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
>     self.run()
>   File "/usr/lib/python2.7/threading.py", line 754, in run
>     self.__target(*self.__args, **self.__kwargs)
>   File "/usr/local/lib/python2.7/dist-packages/grpc/_server.py", line 673, in 
> _serve
>     event = state.completion_queue.poll()
>   File "src/python/grpcio/grpc/_cython/_cygrpc/completion_queue.pyx.pxi", 
> line 114, in grpc._cython.cygrpc.CompletionQueue.poll 
> (src/python/grpcio/grpc/_cython/cygrpc.c:10482)
> KeyboardInterrupt
> 
> Apparently the code is stuck at the poll(). I am guessing this has something 
> to do with the threading.

IIRC, Ryu cannot cooperate with the blocking functionality on the C native 
thread.
This constraint is caused by "eventlet" which is networking library and this 
library
is incompatible with the native threads.
gevent which is the similar project of eventlet reports this issue;
  https://github.com/gevent/gevent/issues/786  

I don't know if possible, I recommend you to use gRPC without blocking mode.

Thanks,
Iwase


> 
> Any input will be welcome, or experience with running GRPC servers alongside 
> Ryu apps, thanks!
> 
> Best,
> Leonard
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Ryu-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/ryu-devel
> 

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to