File: util.py

package info (click to toggle)
python-socksipy 1.6.8%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 176 kB
  • sloc: python: 933; makefile: 4
file content (23 lines) | stat: -rw-r--r-- 718 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import time
from socket import socket, error, AF_INET, SOCK_STREAM


def wait_for_socket(server_name, host, port, timeout=2):
    ok = False
    for x in range(10):
        try:
            print('Testing [%s] proxy server on %s:%d'
                  % (server_name, host, port))
            s = socket(AF_INET, SOCK_STREAM)
            s.connect((host, port))
            s.close()
        except error as ex:
            print('ERROR', ex)
            time.sleep(timeout/10.0)
        else:
            print('Connection established')
            ok = True
            break
    if not ok:
        raise Exception('The %s proxy server has not started in %d seconds'
                        % (server_name, timeout))