0
此腳本檢查FTP並按計劃的時間間隔下載文件。在Python中處理的信號導致FTP連接中斷
向它發送正確的信號(SIGUSR1)應該使它正常關閉,等待checkAll完成,如果正在運行。
class ScheduledFtpCheck(FtpCheck, Scheduler):
def __init__(self):
...
self.aborted, self.checking = False, False
def abort(self, *args, **kwargs):
self.aborted = True
if not self.checking: self.quit()
def checkAll(self):
if not self.isAborted():
self.checking = True
self.checkAll()
self.checking = False
if self.aborted: self.quit()
...
def main():
sch = ScheduledFtpCheck()
signal.signal(signal.SIGUSR1, sch.abort)
sch.start()
的問題是,我收到了被中斷的系統調用,使ftplib.FTP過早退出:
Traceback (most recent call last):
File "/root/my-applications/sensor/sensor/lib/importutils2.py", line 137, in connectAndCheckAll
try: self.checkAll()
...
File "/usr/lib/python2.6/ftplib.py", line 182, in getline
line = self.file.readline()
File "/usr/lib/python2.6/socket.py", line 406, in readline
data = self._sock.recv(self._rbufsize)
error: [Errno 4] Interrupted system call
所以我的腳本處理信號正常,但計劃檢查不。
爲什麼?我怎樣才能防止它?
感謝您的支持