#!/usr/bin/python2.4 # by pts@fazekas.hu at Wed Feb 18 15:42:05 CET 2009 import errno import os import select import signal import thread pid = os.getpid() print 'main pid=%d' % pid read_fd, write_fd = os.pipe() def Handler(arg1, arg2): print 'handler arg1=%r arg2=%r' % (arg1, arg2) os.write(write_fd, 'W') signal.signal(signal.SIGUSR1, Handler) can_kill_mutex = thread.allocate_lock() def SendSIGUSR1(): print 'S' can_kill_mutex.acquire() print 'T' os.kill(pid, signal.SIGUSR1) print 'U' for i in xrange(1<<30): print '---', i can_kill_mutex.acquire() thread.start_new_thread(SendSIGUSR1, ()) print 'A' can_kill_mutex.release() print 'B' try: got = select.select([read_fd], [], []) except select.error, e: if e.args[0] != errno.EINTR: raise got = str(e) print 'select got=%r' % (got,) print 'read str=%r' % (os.read(read_fd, 1),) can_kill_mutex.release()