ansys / pyedb-core

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

Cannot launch session with session context manager #369

Closed isaacansys closed 6 months ago

isaacansys commented 6 months ago

πŸ” Before submitting the issue

🐞 Description of the bug

Attempting to launch a local server session using the provided context manager and Ansys EM 2024 R1 results in a "local server failed to start properly" message.

πŸ“ Steps to reproduce

In a virtual environment with ansys-edb-core installed and the ANSYSEM_ROOT241 environment variable set to an installation of Ansys EM 2024 R1, run the following script:

import os

from ansys.edb.core.session import session

with session(os.environ["ANSYSEM_ROOT241"]):
    pass

Output:

(venv) PS C:\scratch> python .\new_session.py
Local server failed to start properly. Trying to shut down gracefully...
CRITICAL - Uncaught exception
Traceback (most recent call last):
  File "C:\scratch\venv\lib\site-packages\ansys\edb\core\session.py", line 287, in wait_server_ready
    if self.local_server_proc.wait(10):
  File "C:\Program Files\Python310\lib\subprocess.py", line 1209, in wait
    return self._wait(timeout=timeout)
  File "C:\Program Files\Python310\lib\subprocess.py", line 1509, in _wait
    raise TimeoutExpired(self.args, timeout)
subprocess.TimeoutExpired: Command '['C:\\Program Files\\AnsysEM\\v241\\Win64\\EDB_RPC_Server.EXE', '-p', '50051']' timed out after 10 seconds

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\scratch\venv\lib\site-packages\ansys\edb\core\session.py", line 508, in session
    MOD.current_session.connect()
  File "C:\scratch\venv\lib\site-packages\ansys\edb\core\session.py", line 238, in connect
    self.start_server()
    self.wait_server_ready()
  File "C:\scratch\venv\lib\site-packages\ansys\edb\core\session.py", line 290, in wait_server_ready
    raise EDBSessionException(ErrorCode.STARTUP_TIMEOUT, stdout)
ansys.edb.core.inner.exceptions.EDBSessionException: Could not start local server: Time out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\scratch\new_session.py", line 6, in <module>
    with session(os.environ["ANSYSEM_ROOT241"], 50051):
  File "C:\Program Files\Python310\lib\contextlib.py", line 135, in __enter__
    return next(self.gen)
  File "C:\scratch\venv\lib\site-packages\ansys\edb\core\session.py", line 515, in session
    MOD.current_session.disconnect()
AttributeError: 'NoneType' object has no attribute 'disconnect'
(venv) PS C:\scratch> 

πŸ’» Which operating system are you using?

Windows

πŸ“€ Which ANSYS version are you using?

2024 R1

🐍 Which Python version are you using?

3.10

πŸ“¦ Installed packages

ansys-api-edb==1.0.0
ansys-edb-core==0.1.2
grpcio==1.60.1
protobuf==3.20.3
isaacansys commented 6 months ago

Root cause appears to be this check of the server's standard output. The check is looking for a period after "127.0.0.1" but the 2024 R1 and 2023 R2 servers instead print a colon and the port number, e.g.:

(venv) PS C:\git\Ansys\pyedb> & 'C:\Program Files\AnsysEM\v241\Win64\EDB_RPC_Server.exe'
Server listening on 127.0.0.1:50051
(venv) PS C:\git\Ansys\pyedb> & 'C:\Program Files\AnsysEM\v241\Win64\EDB_RPC_Server.exe'
Server listening on 127.0.0.1:50051
(venv) PS C:\git\Ansys\pyedb> & 'C:\Program Files\AnsysEM\v232\Win64\EDB_RPC_Server.exe'
Server listening on 127.0.0.1:50051