File: __init__.py

package info (click to toggle)
python-async 0.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 232 kB
  • ctags: 280
  • sloc: python: 1,515; ansic: 846; makefile: 2
file content (42 lines) | stat: -rw-r--r-- 1,053 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""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
	import sys
	
	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
	try:
		signal.signal(signal.SIGINT, thread_interrupt_handler)
	except ValueError:
		# happens if we don't try it from the main thread
		print >> sys.stderr, "Failed to setup thread-interrupt handler. This is usually not critical"
	# END exception handling


#} END init

_init_atexit()
_init_signals()


# initial imports
from task import *
from pool import *
from channel import *