The psycogreen package makes it possible for psycopg2 to work with coroutine libraries, using asynchronous calls internally but offering a blocking interface so that regular code can run unmodified. While Psycopg offers coroutine support, the main module is a C extension that cannot be monkey-patched to become coroutine-friendly. Instead it exposes a hook that coroutine libraries can use to install a function integrating with their event scheduler. Psycopg will call the function whenever it executes a libpq call that may block. psycogreen is a collection of "wait callbacks" that can be used to integrate Psycopg with different coroutine libraries. psycogreen is currently mainly useful for integration with gevent.
|Tags||Database Python psycopg2 Asynchronous eventlet gevent postgresql|