Skip to content

fix blockon forrever lock #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions pytest_twisted.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ class WrongReactorAlreadyInstalledError(Exception):
pass


class _config:
external_reactor = False


class _instances:
gr_twisted = None
reactor = None
Expand All @@ -23,7 +27,7 @@ def pytest_namespace():


def blockon(d):
if _instances.reactor.running:
if _config.external_reactor:
return block_from_thread(d)

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


def init_twisted_greenlet():
if _instances.reactor is None:
if _instances.reactor is None or _instances.gr_twisted:
return

if not _instances.gr_twisted and not _instances.reactor.running:
if not _instances.reactor.running:
_instances.gr_twisted = greenlet.greenlet(_instances.reactor.run)
# give me better tracebacks:
failure.Failure.cleanFailure = lambda self: None
else:
_config.external_reactor = True


def stop_twisted_greenlet():
Expand Down
4 changes: 3 additions & 1 deletion testing/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,10 @@ def test_blockon_in_hook(testdir):

def pytest_configure(config):
pt.init_default_reactor()
d = defer.Deferred()
d, d2 = defer.Deferred(), defer.Deferred()
reactor.callLater(0.01, d.callback, 1)
reactor.callLater(0.02, d2.callback, 1)
pt.blockon(d)
pt.blockon(d)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intentionally blocking on d twice and ignoring d2?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just typo, thanks for noticing

""")
testdir.makepyfile("""
Expand Down