• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

psycogreen/H10-Oct-2012-8857

psycogreen.egg-info/H03-May-2022-10274

tests/H10-Oct-2012-11072

tools/H10-Oct-2012-2817

COPYINGH A D29-Sep-20121.4 KiB2622

MANIFEST.inH A D10-Oct-2012140 54

PKG-INFOH A D10-Oct-20124.6 KiB10274

README.rstH A D10-Oct-20123.4 KiB8760

setup.cfgH A D10-Oct-201259 64

setup.pyH A D10-Oct-2012878 3828

README.rst

1psycogreen -- psycopg2 integration with coroutine libraries
2===========================================================
3
4The `psycogreen`_ package enables psycopg2 to work with coroutine libraries,
5using asynchronous calls internally but offering a blocking interface so that
6regular code can run unmodified.
7
8`Psycopg`_ offers `coroutines support`__ since release 2.2. Because the main
9module is a C extension it cannot be monkey-patched to become
10coroutine-friendly. Instead it exposes `a hook`__ that coroutine libraries can
11use to install a function integrating with their event scheduler. Psycopg will
12call the function whenever it executes a libpq call that may block.
13`psycogreen` is a collection of "wait callbacks" useful to integrate Psycopg
14with different coroutine libraries.
15
16.. _psycogreen: https://bitbucket.org/dvarrazzo/psycogreen
17.. _Psycopg: http://initd.org/psycopg/
18.. __: http://initd.org/psycopg/docs/advanced.html#support-to-coroutine-libraries
19.. __: http://initd.org/psycopg/docs/extensions.html#psycopg2.extensions.set_wait_callback
20
21
22Module ``psycogreen.eventlet``
23------------------------------
24
25`Eventlet`_ currently supports Psycopg out-of-the-box and ``psycogreen`` is not
26necessary. See `the documentation`__ for patching instruction.
27
28.. _Eventlet: http://eventlet.net/
29.. __: http://eventlet.net/doc/patching.html#monkeypatching-the-standard-library
30
31If for any reason you want to avoid using Eventlet monkeypatching you can use
32``psycogreen.eventlet.patch_psycopg()``.
33
34Function ``psycogreen.eventlet.patch_psycopg()``
35    Enable async processing in Psycopg integrated with the Eventlet events
36    loop.  It is performed by registering ``eventlet_wait_callback()`` as
37    psycopg2 wait callback.
38
39Function ``psycogreen.eventlet.eventlet_wait_callback(conn)``
40    A wait callback integrating with Eventlet events loop.
41
42An example script showing concurrent usage of ``psycopg2`` with ``urlopen()``
43with Eventlet is available in |tests/test_eventlet.py|__.
44
45.. |tests/test_eventlet.py| replace:: ``tests/test_eventlet.py``
46.. __: https://bitbucket.org/dvarrazzo/psycogreen/src/master/tests/test_eventlet.py
47
48
49Module ``psycogreen.gevent``
50----------------------------
51
52In order to use psycopg2 asynchronously with `gevent`_ you can use
53``psycogreen.gevent.patch_psycopg()``.
54
55Function ``psycogreen.gevent.patch_psycopg()``
56    Enable async processing in Psycopg integrated with the gevent events
57    loop.  It is performed by registering ``gevent_wait_callback()`` as
58    psycopg2 wait callback.
59
60Function ``psycogreen.gevent.gevent_wait_callback(conn)``
61    A wait callback integrating with gevent events loop.
62
63An example script showing concurrent usage of ``psycopg2`` with ``urlopen()``
64with gevent is available in |tests/test_gevent.py|__.
65
66.. _gevent: http://www.gevent.org/
67.. |tests/test_gevent.py| replace:: ``tests/test_gevent.py``
68.. __: https://bitbucket.org/dvarrazzo/psycogreen/src/master/tests/test_gevent.py
69
70
71uWSGI green threads
72-------------------
73
74Roberto De Ioris is writing uGreen__, a green thread implementation on top of
75the `uWSGI async platform`__.
76
77.. __: http://projects.unbit.it/uwsgi/wiki/uGreen
78.. __: http://projects.unbit.it/uwsgi/
79
80He has performed some tests using both `psycopg2 async support`__ and
81`psycopg2 green support`__ and has reported no problem in their stress tests
82with both the async styles.
83
84.. __: http://projects.unbit.it/uwsgi/browser/tests/psycopg2_green.py
85.. __: http://projects.unbit.it/uwsgi/browser/tests/psycogreen_green.py
86
87