对此特定脚本中的“ threading.BoundedSemaphore”的作用感到困惑

时间:2019-09-09 23:12:23

标签: python python-3.x semaphore

我很难理解这个特定代码中的“ Bounded.Semaphore”正在做什么。我在YouTube上查找了示例和视频,没有任何帮助。 这是完整的代码:https://github.com/tatmush/violentPython3/blob/master/Chapter-2/3-sshBrute.py

maxConnections = 5

connectionLock = BoundedSemaphore(value=maxConnections)
try:
    s=pxssh.pxssh()
    s.login(host, user, password)
    print('[+]Password Found: ' + password)
    found=True
    print('Found in CONNECT: {}'.format(found))
except Exception as e:
    print(e)
    if 'read_nonblocking' in str(e):
        logging.debug('Now in if statement')
        fails+=1
        time.sleep(5)
        connect(host, user, password, False)

    elif 'synchronize with original prompt' in str(e):
        logging.debug('Now in elif')
        time.sleep(1)
        connect(host, user, password, False)
finally:
    if release: connectionLock.release()

0 个答案:

没有答案