Skip to content

Commit c2f9013

Browse files
author
Yuriy Bilopolov
committed
fix blockon lock forrever
1 parent eac7976 commit c2f9013

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

pytest_twisted.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ class WrongReactorAlreadyInstalledError(Exception):
1313
pass
1414

1515

16+
class _config:
17+
external_reactor = False
18+
19+
1620
class _instances:
1721
gr_twisted = None
1822
reactor = None
@@ -23,7 +27,7 @@ def pytest_namespace():
2327

2428

2529
def blockon(d):
26-
if _instances.reactor.running:
30+
if _config.external_reactor:
2731
return block_from_thread(d)
2832

2933
return blockon_default(d)
@@ -61,13 +65,15 @@ def inlineCallbacks(fun, *args, **kw):
6165

6266

6367
def init_twisted_greenlet():
64-
if _instances.reactor is None:
68+
if _instances.reactor is None or _instances.gr_twisted:
6569
return
6670

67-
if not _instances.gr_twisted and not _instances.reactor.running:
71+
if not _instances.reactor.running:
6872
_instances.gr_twisted = greenlet.greenlet(_instances.reactor.run)
6973
# give me better tracebacks:
7074
failure.Failure.cleanFailure = lambda self: None
75+
else:
76+
_config.external_reactor = True
7177

7278

7379
def stop_twisted_greenlet():

testing/test_basic.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,10 @@ def test_blockon_in_hook(testdir):
146146
147147
def pytest_configure(config):
148148
pt.init_default_reactor()
149-
d = defer.Deferred()
149+
d, d2 = defer.Deferred(), defer.Deferred()
150150
reactor.callLater(0.01, d.callback, 1)
151+
reactor.callLater(0.02, d2.callback, 1)
152+
pt.blockon(d)
151153
pt.blockon(d)
152154
""")
153155
testdir.makepyfile("""

0 commit comments

Comments
 (0)