Skip to content
Snippets Groups Projects
Commit 91775880 authored by Fabian Wachsmann's avatar Fabian Wachsmann
Browse files

With port finder

parent 25b6cf9f
No related branches found
No related tags found
No related merge requests found
Pipeline #96665 failed
...@@ -10,6 +10,7 @@ import os ...@@ -10,6 +10,7 @@ import os
import subprocess import subprocess
#import hdf5plugin #import hdf5plugin
import argparse import argparse
import socket
def parse_args(): def parse_args():
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
...@@ -51,7 +52,19 @@ if not os.path.isfile(ssl_keyfile) or not os.path.isfile(ssl_certfile): ...@@ -51,7 +52,19 @@ if not os.path.isfile(ssl_keyfile) or not os.path.isfile(ssl_certfile):
subprocess.run(openssl_cmd, check=True) subprocess.run(openssl_cmd, check=True)
port=9010 def is_port_free(port, host="localhost"):
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
return s.connect_ex((host, port)) != 0 # Returns True if the port is free
def find_free_port(start=5000, end=5100, host="localhost"):
for port in range(start, end + 1):
if is_port_free(port, host):
return port
return None # No free ports found
port = find_free_port(9000,9100)
if not port:
raise ValueError("Could not find a free port for service")
nest_asyncio.apply() nest_asyncio.apply()
chunks={} chunks={}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment