Skip to content

Test server before returning it in ansys.dpf.core.server.connect_to_server #414

@PProfizi

Description

@PProfizi

Before submitting the issue

  • I have checked for Compatibility issues
  • I have searched among the existing issues
  • I am using a Python virtual environment

Description of the bug

When using ansys-dpf-core 0.5.2 with InProcess by default and starting a DPF server on a docker, then trying to connect to it from outside, the connect_to_server method might finish and return a GrpcServer, however consequent commands can fail due to the server actually not being ready.

The connect_to_server method should further test the connection before returning the DpfServer object.
One should also make a GrpcServer method available to test the status of the server, much like what is done in check_ansys_grpc_dpf_version function. This could also be done for the LegacyGrpcServer.

A trick used by @janvonrickenbach to check the server is finally ready is:

timeout = 5
import time

tstart = time.time()
while ((time.time() - tstart) < timeout):
    time.sleep(0.001)
    try:
        server.version
        break
    except Exception as e:
        pass
server.version

For information this can take up to 3 seconds depending on the docker environment.

Steps To Reproduce

Run DPF on docker
Then connect to it
server = connect_to_server(...)
Then ask for its version
version = server.version

Which Operating System are you using?

Linux

Which Python version are you using?

3.7

Installed packages

NA

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions