ansys / pyedb-core

Ansys Electronics Database Python Client Package
https://edb.core.docs.pyansys.com/
MIT License
2 stars 1 forks source link

FEATURE: Checking for port used before starting server session #393

Closed chenchienjacklin closed 4 months ago

chenchienjacklin commented 4 months ago

376

chenchienjacklin commented 4 months ago

Resue the session if it already exists. Will need to implement health check to attach to a running server. Tested scenarios

if MOD.current_session is not None:
    MOD.current_session.disconnect()
print("Before launch_session")
print(f"MOD.current_session: {MOD.current_session}")

# If there is no active session and no server executable listening on the provided port, start the server executable and attach to it.
session = launch_session(EXE_DIR, 50051)
print(f"session: {session}")

# If a session already exists on the provided port, reuse it
session2 = launch_session(EXE_DIR, 50051)
print(f"session: {session2}")

# If a session already exists but it is on a different port than requested, throw an error
try:
    session3 = launch_session(EXE_DIR, 50052)
except Exception as e:
    print(e)

Results

Before launch_session
MOD.current_session: None
session: <ansys.edb.core.session._Session object at 0x000001888E41B940>
session: <ansys.edb.core.session._Session object at 0x000001888E41B940>
There can be only one session active at a time.