我需要有关脚本的帮助,以使用不同的线程遍历多个列表。
我已经尝试了很多方法,但是我看不出我的线程如何异步迭代相同的列表而不会发生冲突或执行相同的数组!
pass.txt
包含类似于pythonnewbie:pass123456
的行。proxy.txt
包含类似于128.14.52.163:8080
的行。我在所有测试中收到的主要错误是“ UnboundLocalError”。
我需要找到一种异步方法来使线程使专业计数器恢复为-1。
pass.txt包含22257行,proxy.txt 4516,代理列表到达末尾时将停止!
#!/usr/bin/env python
#!-*- coding:utf-8 -*-
import os, sys, time, random
import Queue
from threading import Thread, ThreadError
combolist = open('/pass.txt').read().splitlines()
proxylist = open('/proxy.txt').read().splitlines()
proxycut = [x.split(':', 1)[0] for x in proxylist]
portcut = [x.split(':', 1)[1] for x in proxylist]
combomailcut = [x.split(':', 1)[0] for x in combolist]
combopasscut = [x.split(':', 1)[1] for x in combolist]
pro = -1
orp = -1
valid = -1
def brunch(pro, orp):
try:
PROXY = proxycut[pro]
PORT = int(portcut[pro])
except IndexError:
pro = -1
ACCOUNT = combomailcut[orp]
PASSWORD = combopasscut[orp]
print("Proxy traffic: {}:{}".format(PROXY, PORT))
print("On teste avec {}:{}".format(ACCOUNT, PASSWORD))
for x in combomailcut:
pro += 1
orp += 1
try:
t = Thread(target=brunch, args=(pro, orp))
t.start()
except IndexError:
pro = -1
pro += 1
t = Thread(target=brunch, args=(pro, orp))
t.start()
如果达到UnboundError,但我希望它的专业计数器回到-1,但它不起作用...
On teste avec prinwesla:cyy813zRvR
Proxy traffic: 187.121.178.53:20183
On teste avec agsaylor:Annabell01
Exception in thread Thread-4517:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 754, in run
self.__target(*self.__args, **self.__kwargs)
File "dofus.py", line 28, in brunch
print("Proxy traffic: {}:{}".format(PROXY, PORT))
UnboundLocalError: local variable 'PROXY' referenced before assignment
Exception in thread Thread-4520:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 754, in run
self.__target(*self.__args, **self.__kwargs)
File "dofus.py", line 28, in brunch
print("Proxy traffic: {}:{}".format(PROXY, PORT))
UnboundLocalError: local variable 'PROXY' referenced before assignment