0
현재 ssh/telnet 라이브러리를 사용하는 스레드 목록과 관련된 문제를 다루고 있습니다. 주 스레드에 대한 일부 시간 초과 값에서 스레드가 모든 리소스를 닫고 자체 종료하도록 지시하고 싶습니다. 여기에 내가하고 싶은 무엇 내 코드리소스를 닫기 위해 스레드를 가르치십시오.
import threading
import time
import socket
threads = []
def do_this(data):
"""this function is not the implementation this code may not be valid"""
w = socket.create_connection(data, 100)
while True:
if 'admin' in w.read(256):
break
w.close
for data in data_list:
t = threading.Thread(target=do_this, args=(data,))
t.start()
threads.append(t)
end_time = time.time()+120
for t in threads:
t.join(end_time-time.time())
모습의 예는이
def do_this(data):
w = socket.create_connection(data, 100)
while True:
if 'admin' in w.read(256):
break
w.close()
on signal:
w.close()
return
두 번째 닫기 블록에서 스레드를 죽이기 위해''on signal''을 원하십니까? – wnnmaw