mirror of https://github.com/celery/kombu.git
gevent: Make sure synchronous calls are blocking
This commit is contained in:
parent
4b50b6ba38
commit
3f28abcb58
|
@ -12,23 +12,44 @@ except ImportError:
|
||||||
ctypes = None
|
ctypes = None
|
||||||
|
|
||||||
|
|
||||||
blocking = None
|
def __how_to_block():
|
||||||
try:
|
## -eventlet-
|
||||||
from eventlet.patches import is_monkey_patched as is_eventlet
|
try:
|
||||||
import socket
|
from eventlet.patches import is_monkey_patched as is_eventlet
|
||||||
|
import socket
|
||||||
|
|
||||||
if is_eventlet(socket):
|
if is_eventlet(socket):
|
||||||
from eventlet import spawn
|
from eventlet import spawn
|
||||||
|
|
||||||
def blocking(fun, *args, **kwargs):
|
def __blocking__(fun, *args, **kwargs):
|
||||||
return spawn(fun, *args, **kwargs).wait()
|
return spawn(fun, *args, **kwargs).wait()
|
||||||
except ImportError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
if blocking is None:
|
return __blocking__
|
||||||
def blocking(fun, *args, **kwargs):
|
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 fun(*args, **kwargs)
|
||||||
|
|
||||||
|
return __blocking__
|
||||||
|
|
||||||
|
blocking = __how_to_block()
|
||||||
|
|
||||||
|
|
||||||
def say(m, *s):
|
def say(m, *s):
|
||||||
sys.stderr.write(str(m) % s + "\n")
|
sys.stderr.write(str(m) % s + "\n")
|
||||||
|
|
Loading…
Reference in New Issue