How to exchange data bewteen Slicer instance and Python CLI during runtime

For my project I need to get the table position of a CT system. To get this information I need to connect via SSH to a server and call a command which will then continously write the table position to the stdout. Connecting via SSH and reading the stdout is easily done, though the workflow is basically to endlessly read from the stdout (i.e. an endless loop which reads the current table position).
From what I understood so far, I wanted to create a Python CLI module which does the interfacing with the CT system because CLI is the suggested way for running “long running tasks” in the background. Though now I read somewhere that the results from a CLI are only written back to the scene nodes after the CLI finished the processing. This will not work in my case as the process should run until the application stops and should continously update a transform node.
Is there another way to run such a task in an asynchronous way and update the transform nodes accordingly?

OpenIGTLink is designed for exactly this use case. You can connect to a wide range of imaging and tracking devices using this protocol from Slicer (using OpenIGTLink extension).

If you use an optical tracker (NDI, Optirak, Ascension, Claron, etc.), surgical navigation system (BrainLab or Medtronic), or some other position sensors then you can use the Plus toolkit for this and then you don’t need to implement anything.

Alternatively, you can implement OpenIGTLink in your server (instead of a custom protocol). If all else fails, you can write a small Python script that continuously queries the SSH server and makes the positions available via OpenIGTLink using pyigtl.

Also note that you can perform all kinds of tool calibrations and patient registrations that are needed for image-guided therapy, using SlicerIGT extension.

Thanks for the many suggestions. For most of our interfaces we are already using OpenIGTLink and we make also use of SlicerIGT. Unfortunately we do not have direct access to the CT system. The only interface that we can use is the SSH connection.
But if I understood correctly, I could create a stand-alone Python application that is connecting to the CT via SSH and acts as an OpenIGTLink server to which our Slicer application connects. This should work, right? Did not think about that, thanks for the ideas!

Exactly. You can launch this small Python script from Slicer similarly to how slicer.util._executePythonModule works (just skip the part in the end that wait until the processing is completed) or using standard Python subprocess functions.