AsyncResult vs I/O Blocking on Greenlet Performance

189 weergaven
Naar het eerste ongelezen bericht

umut kahrıman

ongelezen,
25 sep 2019, 15:45:1025-09-2019
aan 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

ongelezen,
30 sep 2019, 13:17:5330-09-2019
aan 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 :)
Allen beantwoorden
Auteur beantwoorden
Doorsturen
0 nieuwe berichten