sniffio icon indicating copy to clipboard operation
sniffio copied to clipboard

Add support for synchronous event loops

Open tzickel opened this issue 5 years ago • 4 comments
trafficstars

The same principle that exists in the asynchronous world, exists in the synchronous world as well.

I've been bitten enough by gevent's monkey patching, that I think that if library writers had an option to detect a code is running via a greenlet or normal (threaded?), it could create code that automatically knows which primitives to use.

@jamadden This could make libraries like this (which is the basis of httpx) auto detect and use gevent as well (without monkey patching) ? https://github.com/encode/httpcore/tree/master/httpcore/_backends

tzickel avatar May 24 '20 09:05 tzickel

I just don't understand how this would make the code manifest the necessary await etc. statements. Enlighten us please?

agronholm avatar Mar 10 '21 21:03 agronholm

there's also the case for twisted in greenlet or asyncio in greenlet (and them both), eg running async sqlalchemy on pytest-twisted

graingert avatar Mar 10 '21 21:03 graingert

I do not understand how gevent is related to async/await. As said in the OP, I would like the option for sniffio to be able to report synchronous event loops such as running inside a greenlet. Then when writing for example a sync library like redis-py it could query if it's running under a greenlet and do different code instead of using regular I/O (thus not requiring monkey patching).

tzickel avatar Mar 11 '21 13:03 tzickel

Ah, I got confused. Nevermind!

agronholm avatar Mar 11 '21 13:03 agronholm