簡體   English   中英

Python uTorrent通知腳本不會終止

[英]Python uTorrent notification script doesnt terminate

我創建了一個小的python腳本,當使用uTorrent在ubuntu 12.04盒子上下載洪流時發送通知。 當我運行pgrep -l torrent時,我可以看到Scipt的負載,並且無法殺死它們。 utorrent通過傳遞torrent名稱調用腳本。 該腳本可以正常運行並在從終端運行時退出,但在utorrent調用時不會關閉。 我嘗試將sys.exit()添加到腳本的底部,但它沒有停止該過程,也沒有停止發送通知。

我能做些什么來使小便變得更緊密嗎? 還有任何想法如何消除這些進程? 我嘗試殺死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

james@Netb$ 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

試試看,在運行腳本時,請確保在調用腳本時執行/path/to/script.py >> debug.txt以保存utorrent調試信息。 這應該為您提供更好的錯誤處理,並在完成后顯式關閉套接字。 我還添加了一個小的超時。

我猜想套接字是掛在腳本的一部分中的。 調用shutdown將停止所有流量,然后關閉將關閉套接字。

#!/usr/bin/python

import logging
import os
import socket
import sys

def network_notify(name):
    hosts = ['192.168.0.4', '192.168.0.6']  #server IP
    port = 50000 
    size = 1024
    title = 'Torrent Downloaded'

    for host in hosts:
        try:
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            # Set the socket to timeout after 10 seconds
            s.settimeout(10.0) 
            s.connect((host, port))
        except socket.error, socket.timeout:
            logging.error('Something is wrong with host: %s' % host)
            continue

        # Send the data
        s.sendall('"%s" "%s"' % (title, name))
        data = s.recv(size)

        # Shutdown and close the socket 
        s.shutdown(socket.SHUT_RDWR)
        s.close()

    if len(sys.argv) > 1:
        name = ' '.join(sys.argv[1:])
        network_notify(name)
    sys.exit()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM