nose would try to import this module and fail if twisted wasn't present; cleaned up the import so this doesn't happen. Also fixed aliasing of module name.
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
from twisted.internet import defer
|
||||
from twisted.python import failure
|
||||
from eventlet.api import spawn, getcurrent
|
||||
from eventlet.hubs import get_hub
|
||||
|
||||
@@ -13,17 +11,17 @@ def block_on(deferred):
|
||||
else:
|
||||
cur[0].switch(value)
|
||||
return value
|
||||
def eb(failure):
|
||||
def eb(fail):
|
||||
if cur:
|
||||
if getcurrent() is cur[0]:
|
||||
synchronous.append((None, failure))
|
||||
synchronous.append((None, fail))
|
||||
else:
|
||||
failure.throwExceptionIntoGenerator(cur[0])
|
||||
fail.throwExceptionIntoGenerator(cur[0])
|
||||
deferred.addCallbacks(cb, eb)
|
||||
if synchronous:
|
||||
result, failure = synchronous[0]
|
||||
if failure is not None:
|
||||
failure.raiseException()
|
||||
result, fail = synchronous[0]
|
||||
if fail is not None:
|
||||
fail.raiseException()
|
||||
return result
|
||||
try:
|
||||
return get_hub().switch()
|
||||
@@ -34,12 +32,14 @@ def _putResultInDeferred(deferred, f, args, kwargs):
|
||||
try:
|
||||
result = f(*args, **kwargs)
|
||||
except:
|
||||
from twisted.python import failure
|
||||
f = failure.Failure()
|
||||
deferred.errback(f)
|
||||
else:
|
||||
deferred.callback(result)
|
||||
|
||||
def deferToGreenThread(func, *args, **kwargs):
|
||||
from twisted.internet import defer
|
||||
d = defer.Deferred()
|
||||
spawn(_putResultInDeferred, d, func, args, kwargs)
|
||||
return d
|
||||
|
Reference in New Issue
Block a user