AsyncResult vs I/O Blocking on Greenlet Performance

168 views
Skip to first unread message

umut kahrıman

unread,
Sep 25, 2019, 3:45:10 PM9/25/19
to gevent: coroutine-based Python network library
Hi,

I am wondering if there is a difference between using AsyncResult with wait() and I/O blocking code. To explain more clearly imagine you are calling some function and waiting for some event to fire, in this case, we can use AsyncResult to block the code until the event fires. On the other hand, let us send HTTP request to some server and wait for some JSON response, this request blocks the code until it returns some data. Should I always use AsyncResult when blocking the code or is it okay to block code with I/O process?  I want to block the code in either case.

All these processes will run in a spawned greenlet. What I wondering is that blocking code with I/O will ever slow down other spawned greenlets?

Thanks.

Kevin Tewouda

unread,
Sep 30, 2019, 1:17:53 PM9/30/19
to gevent: coroutine-based Python network library
Hi Umut,
I think the goal in either case is to yield to the hub to prevent blocking the entire event loop (so give a chance to run other pending greenlets). AsyncResult is cooperative so it will yield without problem but requests will not by default because it uses the standart network library. You need to monkeypatch requests.
Some resources that can help you
Hope this will help you :)
Reply all
Reply to author
Forward
0 new messages