summaryrefslogtreecommitdiff
path: root/lib/git/async/__init__.py
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2010-06-11 16:25:27 +0200
committerSebastian Thiel <byronimo@gmail.com>2010-06-11 16:29:55 +0200
commit1873db442dc7511fc2c92fbaeb8d998d3e62723d (patch)
tree75da67c3d50cef457808c3b8ba9bdbb2b088c1fa /lib/git/async/__init__.py
parentf606937a7a21237c866efafcad33675e6539c103 (diff)
downloadgitpython-1873db442dc7511fc2c92fbaeb8d998d3e62723d.tar.gz
Improved shutdown handling - although its impossible to prevent some stderr printing thanks to the underlying threading implementation, we can at least make sure that the interpreter doesn't block during shutdown. Now it appears to be running smoothly
Diffstat (limited to 'lib/git/async/__init__.py')
-rw-r--r--lib/git/async/__init__.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/git/async/__init__.py b/lib/git/async/__init__.py
index 89b9eb47..e212f1b2 100644
--- a/lib/git/async/__init__.py
+++ b/lib/git/async/__init__.py
@@ -1 +1,30 @@
"""Initialize the multi-processing package"""
+
+#{ Initialization
+def _init_atexit():
+ """Setup an at-exit job to be sure our workers are shutdown correctly before
+ the interpreter quits"""
+ import atexit
+ import thread
+ atexit.register(thread.do_terminate_threads)
+
+def _init_signals():
+ """Assure we shutdown our threads correctly when being interrupted"""
+ import signal
+ import thread
+
+ prev_handler = signal.getsignal(signal.SIGINT)
+ def thread_interrupt_handler(signum, frame):
+ thread.do_terminate_threads()
+ if callable(prev_handler):
+ prev_handler(signum, frame)
+ raise KeyboardInterrupt()
+ # END call previous handler
+ # END signal handler
+ signal.signal(signal.SIGINT, thread_interrupt_handler)
+
+
+#} END init
+
+_init_atexit()
+_init_signals()