Coroutine support for Psycopg

Starting from release 2.2, Psycopg offers coroutines support.

Psycopg is a C extension module, so it can't be monkey-patched to be coroutine-friendly. Instead it now exposes a hook where a coroutine library can install its wait code. Psycopg will call the hook whenever it executes a libpq call that may block. Coroutine libraries can implement their "wait callaback" in order to have a chance to schedule a coroutine switch.

In this project there are wait callback implementations for a few coroutine libraries: they are licensed in order to allow their inclusion in the library.


Eventlet supports Psycopg out-of-the-box: Psycopg can be patched together with the standard library. See the documentation.


A wait callback implementation for gevent is provided here: check psyco_gevent.py and this test example.

uWSGI green threads

Roberto De Ioris is writing uGreen, a green thread implementation on top of the uWSGI async platform.

He has performed some tests using both psycopg2 async support and psycopg2 green support and has reported no problem in their stress tests with both the async styles.


Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.