diff --git a/pythonping/__init__.py b/pythonping/__init__.py index 2b3c29e..bb52fea 100644 --- a/pythonping/__init__.py +++ b/pythonping/__init__.py @@ -5,7 +5,7 @@ # this needs to be available across all thread usages and will hold ints -SEED_IDs = [] +SEED_IDs = set() def ping(target, @@ -74,15 +74,16 @@ def ping(target, # seed_id needs to be less than or equal to 65535 (as original code was seed_id = getpid() & 0xFFFF) seed_id = randint(0x1, 0xFFFF) if seed_id not in SEED_IDs: - SEED_IDs.append(seed_id) + SEED_IDs.add(seed_id) break + try: + comm = executor.Communicator(target, provider, timeout, interval, socket_options=options, verbose=verbose, output=out, + seed_id=seed_id, source=source, repr_format=out_format) - comm = executor.Communicator(target, provider, timeout, interval, socket_options=options, verbose=verbose, output=out, - seed_id=seed_id, source=source, repr_format=out_format) + comm.run(match_payloads=match) - comm.run(match_payloads=match) - - SEED_IDs.remove(seed_id) + finally: + SEED_IDs.remove(seed_id) return comm.responses