【发布时间】:2012-04-23 13:05:42
【问题描述】:
我正在运行两个 python 线程 (import threading)。他们俩都在open() 呼叫中被阻止;事实上,他们会尝试打开命名管道以便在其中写入,因此在有人尝试从命名管道读取之前阻塞是一种正常的行为。
简而言之,它看起来像:
import threading
def f():
open('pipe2', 'r')
if __name__ == '__main__':
t = threading.Thread(target=f)
t.start()
open('pipe1', 'r')
当我键入 ^C 时,主线程中的 open() 被中断(引发 IOError 且 errno == 4)。
我的问题是:t 线程仍在等待,我想传播中断行为,以使其也引发IOError。
【问题讨论】:
-
如果在子线程启动前设置 daemon=True 会怎样?
-
仅此而已。而且,我的问题的目的不是杀死线程,我希望他在收到信号后做一些事情(清理)。
标签: python multithreading system-calls interrupted-exception