i'm trying to limit this loop to 4 concurrent jobs:
def testSSH(host, user, password, port):
s = pxssh.pxssh()
try:
if not s.login (host, username=user, password=password, port=port):
print(password)
return False
else:
print(password)
return True
except:
print(password)
return False
passes = "r", "1234", "12345", "123456!", "1234567", "a", "b", "e", "s", "A", "d", "66"
jobs = []
for passw in passes:
thread = threading.Thread(target=testSSH, args=("localhost", "myuser", passw, "22",))
jobs.append(thread)
for j in jobs:
print(threading.active_count())
j.start()
for j in jobs:
j.join()
the code runs fine. however, i cannot seem to limit the concurrent jobs. the threading.active_count() is always the value of passes. any tips? i've tried this question but could make little of it thanks!