Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def create_server_if_none(self):
"""Creates a localhost server if none is alive, yet."""
# Server alive?
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_port = self.read_or_generate_server_port()
try:
sock.connect(('127.0.0.1', server_port))
except socket.error:
# Nope, create one.
print("[continuum] Creating server.")
self.server = Server(server_port, self)
finally:
sock.close()