Skip to content
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

Import lock bug #34

Closed
tomprince opened this issue Mar 28, 2014 · 5 comments · Fixed by #44
Closed

Import lock bug #34

tomprince opened this issue Mar 28, 2014 · 5 comments · Fixed by #44
Labels
Milestone

Comments

@tomprince
Copy link
Contributor

Given sample.py:

from crochet import setup, wait_for_reactor
setup()

from twisted.names.client import lookupAddress

answers, _, _ = wait_for_reactor(lookupAddress)('google.com')

print [
    record.payload.dottedQuad()
    for record in answers
    ]

Running python sample.py finished instantly, but python -c 'import sample fails.

I suspect this might have something to do with the import lock.

@tomprince
Copy link
Contributor Author

Simpler case:

from crochet import setup, wait_for_reactor
setup()
wait_for_reactor(__import__)('sys')

@itamarst
Copy link
Owner

I wonder if this is something Crochet can even solve. My first thought is documenting that one shouldn't run wait_for_reactor and friends on module level.

@tomprince
Copy link
Contributor Author

... or anything called at module level.

@itamarst
Copy link
Owner

Perhaps EventualResult.wait() should throw an exception if imp.lock_held() is true.

@itamarst itamarst added this to the v1.2.0 milestone Mar 29, 2014
@itamarst
Copy link
Owner

itamarst commented Apr 6, 2014

In Python 3.3 (which is minimal supported version anyway) "The locking scheme has changed to per-module locks for the most part. A global import lock is kept for some critical tasks, such as initializing the per-module locks." Which means simply checking imp.lock_held() is insufficient on Python 3, though to be fair deadlocks are much less likely there. I'll probably just punt Python 3 support to another ticket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants