signal.signal(signal.SIGINT,signal.SIG_IGN)
它在我遇到winpexpect部分之前有效,如果winpexpect产生了进程,那么我按下ctrl-c。发生以下错误。
File "xxx.py", line 605, in myFunc
i = thread.expect_list(cpl,timeout=timeout)
File "C:\Python27\lib\site-packages\winpexpect-1.6-py2.7.egg\pexpect.py", line
1325, in expect_list
return self.expect_loop(searcher_re(pattern_list), timeout, searchwindowsize
)
File "C:\Python27\lib\site-packages\winpexpect-1.6-py2.7.egg\pexpect.py", line
1378, in expect_loop
c = self.read_nonblocking (self.maxread, timeout)
File "C:\Python27\lib\site-packages\winpexpect-1.6-py2.7.egg\winpexpect.py", l
ine 955, in read_nonblocking
handle, status, data = self.child_output.get(timeout=timeout)
File "C:\Python27\lib\Queue.py", line 177, in get
self.not_empty.wait(remaining)
File "C:\Python27\lib\threading.py", line 358, in wait
_sleep(delay)
IOError: [Errno 4] Interrupted function call
我检查了winpexpect源代码,它在扫描程序输出时捕获了这个异常,有没有办法告诉它忽略这个异常并在我的主python脚本中处理它? (必须更改winpexpect代码?)
所以换句话说问题可能是“如何忽略模块中捕获的异常并重新引发它,所以外部代码可以在以后捕获它?”