I'm using the GitPython package to access a Git repository from Python. This pulls in the async package. In async/__init__.py
, the following happens:
def _init_signals():
"""Assure we shutdown our threads correctly when being interrupted"""
import signal
# ...
signal.signal(signal.SIGINT, thread_interrupt_handler)
_init_signals()
This works fine if everything is in the main thread. However, when the first import of git
(and thus async
) happens on another thread, things go boom:
ValueError: signal only works in main thread
Since all this runs inside the Django framework, I have no control over threading.
One workaround I've found is to put import async
into settings.py
, which is (apparently) imported on the main thread. However, this needs to be done on a per-install basis, so it's not very nice towards users of my Django app.
I tried catching the exception, but an import that raised an exception does not fully complete, so the next import async
will fail as well.
Can you think of any halfway decent method to work/hack around this problem?
Update: I noticed that Apache's mod_wsgi is smart enough to ignore the signal
call:
[Tue Sep 07 19:53:11 2010] [warn] mod_wsgi (pid=28595): Callback registration for signal 2 ignored.
The problem remains with the Django development server, though.