- 论坛徽章:
- 1
|
本帖最后由 winway1988 于 2013-03-03 15:47 编辑
- [winway@s208 test]$ cat test.py
- #! /usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- import signal
- import threading
- import os
- import time
- def signal_handler(num, stack):
- print num, threading.currentThread().name
- #signal.signal(signal.SIGALRM, signal_handler)
- def wait_for_signal():
- print 'wait_for_signal in', threading.currentThread().name
- time.sleep(10)
- print 'leave wait_for_signal'
- receiver = threading.Thread(target=wait_for_signal, name='receiver')
- receiver.start()
- time.sleep(1)
- signal.alarm(2)
- receiver.join()
- [winway@s208 test]$ ./test.py
- wait_for_signal in receiver
- Alarm clock
复制代码 如果不改变sigalrm的处理方式,好像signal.alarm(2)就是立即生效的,即2秒后主线程退出。注册了自己的处理函数,就延迟了 |
|