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
|
||||
|
||||
|
||||
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")
|
||||
|
|
Loading…
Reference in New Issue