好吧,伙计们,我对python有点陌生,我想制作一个简单的多线程脚本,但它没有按计划进行。那么这个脚本做了什么来获取电话号码列表并将您输入的号码附加到其中并打印它,但是当您选择线程数时让我们说3,而不是对列表中的两个号码执行该功能,它对每个数字执行两次该功能。谁能帮我解决这个问题?
from threading import Thread
def test(list):
i = input('Enter a number: ')
i = phone[k],i
print( i , phone[k])
list = ['+4469545444','+15546343565','+145346465343']
threds = int(input('Enter number of threads : '))
phone = []
with open(list) as ph:
for line in list:
if len(line) > 3:
phone.append(line.strip())
i=0
while True:
Threads = []
for k in range(i,i+threds):
try:
i+=1
if(k >= len(phone)):
break
th = Thread(target=test,args=[phone[k]])
th.daemon = True
th.start()
Threads.append(th)
except Exception as e:
break
for th in Threads:
th.join()
if(i >= len(phone)):
break```