Daniele Varrazzo avatar Daniele Varrazzo committed c2ed31a

Using the gevent.socket implementation of wait_read and wait_write.

Comments (0)

Files changed (1)

gevent/psyco_gevent.py

 import psycopg2
 from psycopg2 import extensions
 
-from gevent.hub import getcurrent, get_hub
-from gevent.core import read_event, write_event, EV_TIMEOUT
-from gevent.hub import sleep as gevent_sleep
+from gevent.socket import wait_read, wait_write
 
 def make_psycopg_green():
     """Configure Psycopg to be used with gevent in non-blocking way."""
 
     extensions.set_wait_callback(gevent_wait_callback)
 
-class Timeout(Exception):
-    pass
-
 def gevent_wait_callback(conn, timeout=-1):
     """A wait callback useful to allow gevent to work with Psycopg."""
     while 1:
         else:
             raise psycopg2.OperationalError(
                 "Bad result from poll: %r" % state)
-
-def _wait_helper(ev, evtype):
-    current = ev.arg
-    if evtype & EV_TIMEOUT:
-        current.throw(Timeout())
-    else:
-        current.switch(ev)
-
-def wait_read(fileno, timeout=-1):
-    evt = read_event(fileno, _wait_helper, timeout, getcurrent())
-    try:
-        switch_result = get_hub().switch()
-        assert evt is switch_result, 'Invalid switch into wait_read(): %r' % (switch_result, )
-    finally:
-        evt.cancel()
-
-
-def wait_write(fileno, timeout=-1):
-    evt = write_event(fileno, _wait_helper, timeout, getcurrent())
-    try:
-        switch_result = get_hub().switch()
-        assert evt is switch_result, 'Invalid switch into wait_write(): %r' % (switch_result, )
-    finally:
-        evt.cancel()
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.