1
我有以下程序:你能解釋下python中的信號處理行爲嗎?
import socket
import sys
import threading
import signal
class serve(threading.Thread):
def __init__(self):
super(serve, self).__init__()
self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.host = ''
self.port = int(sys.argv[1])
def run(self):
self.s.bind((self.host, self.port))
self.s.listen(1)
conn, addr = self.s.accept()
# Call blocks in the following recv
data = conn.recv(1000000)
conn.close()
self.s.close()
def handler(signum, frame):
print "I am the handler: "
signal.signal(signal.SIGHUP, handler)
background = serve()
background.start()
background.join()
有連接到這一點,但不發送任何數據的客戶端程序。問題是什麼時候發送SIGHUP,並且正在拋出「中斷的系統調用」異常。任何想法爲什麼?它發生在python 2.6+和FreeBSD上。我懷疑它與http://bugs.python.org/issue1975有關。