PyIGTL in Docker: Trouble with

Hello, would this be the right place to post this?

I am trying to run a python script that communicates with a 3d slicer extension using the pyigtl library.

However, I am struggling to get the script to communicate with slicer. which is outside the container.

The docker Image is the python:3.10-slim-bullseye, but the same errors occur with the nvidia/cuda:12.3.0-base-ubuntu22.04 image.

Basically, the script runs :

text_server = pyigtl.OpenIGTLinkServer(port=18945, local_server=True)

the code will stall on the next part:

string_message = pyigtl.StringMessage(f, device_name="TextMessage")
text_server.send_message(string_message)

Attempting to set local server to false like so:

text_server = pyigtl.OpenIGTLinkServer(port=18945, local_server=False, iface="0.0.0.0".encode('utf-8'))

reuslts in this error:

Traceback (most recent call last):
  File "/app/server/server.py", line 174, in <module>
    asyncio.run(main())
  File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run
  File "/app/server/server.py", line 170, in main
    await tmsserver.run_server()
  File "/app/server/server.py", line 43, in run_server
    servertms = pyigtl.OpenIGTLinkServer(port=18944, local_server=False, iface="0.0.0.0".encode('utf-8'))
  File "/usr/local/lib/python3.10/dist-packages/pyigtl/comm.py", line 178, in __init__
    self.host = socket.inet_ntoa(fcntl.ioctl(soc.fileno(), 0x8915, struct.pack('256s', ifname[:15]))[20:24])
struct.error: argument for 's' must be a bytes object

the same error occurs if the iface var is set to wifi0 and wlan0 and eth0 stalls like the local version

For added context the script is SlicerTMS/server/server.py in the SlicerTMS github page

Maybe it’s as simple as making sure the port is mapped from the docker instance?

I run the docker containers with
`` bash
docker run -it -p 18944:18944 -p 18945:18945 test
```

and expose both ports in the docker file with

EXPOSE 18944
EXPOSE 18945

but that does not change the errors I am experiencing

was there anything I need to do for port mapping?

would it help if I changed the ports used by the python script?

Thanks

I suggest getting the communication working with pyigtl outside of docker with simple test cases and then try those test cases inside docker to debug.

I have been able to get the same script running in a dev environment on my windows 11 PC,

doing that it connects fine and doesn’t cause any problems.

Otherwise, I will looking into getting simpler test cases running, likely sometime next week

Thanks

Also, forgot to mention a weird bit, I got 3d slicer and the python script to run in the same container and had the same issue

We used OpenIGTLink between Slicer instances in linux docker containers and it worked well.

This is supposed to stall until a client is connected. You can attach a debugger to confirm that indeed the server is waiting on a client to connect.

Do you run pyigtl in Slicer application’s Python environment or in a different Python executable?
In Slicer, you need to use the OpenIGTLinkIF module instead of pyigtl.

HI, Thanks for all the help.

It works now, after uninstalling and reinstalling the OpenIGTLinkIF extension, I could connect using

text_server = pyigtl.OpenIGTLinkServer(port=18945, local_server=False, iface="eth0".encode('utf-8'))
string_message = pyigtl.StringMessage(f, device_name="TextMessage")
text_server.send_message(string_message)

I don’t really know what changed when it was reinstalled but it now showed this connection when on the OpenIGTLinkIF menu.

As for the development environment from before, it was a separate environment to the one associated with the slicer application.

1 Like