我已經創建了一個小型python腳本,用於在ubuntu 12.04盒子上使用uTorrent下載torrent時發送通知。當我運行pgrep -l洪流時,我可以看到scipt的負載並且無法殺死它們。 utorrent調用傳遞torrent名稱的腳本。腳本工作正常,從終端運行時退出,但在utorrent調用它時不會關閉。我嘗試將sys.exit()添加到腳本的底部,但它並未停止該進程並停止發送通知。Python uTorrent通知腳本不會終止
我能做些什麼來使scipt關閉?還有任何想法如何我可以殺死這些進程?我試過殺pkill和htop。
謝謝。
#!/usr/bin/python
import sys
import os
import socket
def network_notify(message):
host = ['192.168.0.4', '192.168.0.6'] #server IP
port = 50000
size = 1024
title = 'Torrent Downloaded'
for i in host:
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((i,port))
except:
None
else:
s.send('\"' + title + '\" \"' +message+'"')
data = s.recv(size)
s.close()
if len(sys.argv) > 1:
name = ' '.join(sys.argv[1:])
network_notify(name)
繼承人和pgrep
[email protected]$ pgrep -l torrent
27516 torrentNotify.p
27518 torrentNotify.p
27520 torrentNotify.p
27521 torrentNotify.p
27522 torrentNotify.p
27529 torrentNotify.p
27531 torrentNotify.p
27540 torrentNotify.p
27541 torrentNotify.p
27545 torrentNotify.p
27546 torrentNotify.p
27550 torrentNotify.p
27551 torrentNotify.p
27552 torrentNotify.p
27553 torrentNotify.p
27555 torrentNotify.p
27558 torrentNotify.p
27567 torrentNotify.p
27570 torrentNotify.p
27571 torrentNotify.p
27573 torrentNotify.p
27574 torrentNotify.p
28959 torrentNotify.p
28965 torrentNotify.p
28970 torrentNotify.p
什麼是這些「wchan」? – 2012-08-04 01:39:38
wchan對他們全部是退出 – James 2012-08-04 02:39:43
你的所有''除:'子句可能隱藏了一些有用的信息。而且,其中一個'socket'方法調用可能被掛起。可能需要添加一些日誌記錄來調試哪一個。 – martineau 2012-08-04 02:54:55