gevent: Make sure synchronous calls are blocking

This commit is contained in:
Ask Solem 2011-01-25 12:54:00 +01:00
parent 4b50b6ba38
commit 3f28abcb58
1 changed files with 33 additions and 12 deletions

View File

@ -12,23 +12,44 @@ except ImportError:
ctypes = None
blocking = None
try:
from eventlet.patches import is_monkey_patched as is_eventlet
import socket
def __how_to_block():
## -eventlet-
try:
from eventlet.patches import is_monkey_patched as is_eventlet
import socket
if is_eventlet(socket):
from eventlet import spawn
if is_eventlet(socket):
from eventlet import spawn
def blocking(fun, *args, **kwargs):
return spawn(fun, *args, **kwargs).wait()
except ImportError:
pass
def __blocking__(fun, *args, **kwargs):
return spawn(fun, *args, **kwargs).wait()
if blocking is None:
def blocking(fun, *args, **kwargs):
return __blocking__
except ImportError:
pass
# -gevent-
try:
from gevent import socket as _gsocket
import socket
if socket.socket is _gsocket.socket:
from gevent import Greenlet
def __blocking__(fun, *args, **kwargs):
return Greenlet.spawn(fun, *args, **kwargs).get()
return __blocking__
except ImportError:
pass
def __blocking__(fun, *args, **kwargs):
return fun(*args, **kwargs)
return __blocking__
blocking = __how_to_block()
def say(m, *s):
sys.stderr.write(str(m) % s + "\n")