Upload Files to Orthanc using rest API hangs

I am building an Orthanc server which does some processing in Python on incoming dicoms before sending them back to a PACS. The data pipeline on the system is as such:

dicom protocol onStableSeries os.execute() RestAPI post onStableSeries(conditional) sendToModality dicom protocol

Scanner -----------------------> Orthanc ------------------------>Lua --------------------> Python (processing) ---------------------->Orthanc ------------------------------------------> Lua -----------------------> Orthanc ----------------------->PACS

The issue I’m having is that the Rest Post called by Python hangs indefinitely. The python script saves the (processed) image to disk, and then uses the bundled RestToolbox.py to post back to Orthanc. If I run the python script manually from cmd, there is no issue, the Rest post only fails when the script is triggered by lua. My suspicion is that the lua script connects to the http port (it uses RestApiGet to save the incoming instances to disk to pass to Python) and does not relinquish the connection before calling the python script, causing a deadlock (I’m guessing that using os.execute causes the lua script to wait for the python script to finish before exiting). I am on windows 7, and using the newest release of Orthanc. If it’s not obvious: I am a complete novice wrt ports/networking etc., so my guess may be totally off.

Is there a way around this? Or perhaps a different routing scheme that avoids the issue entirely? Any help is greatly appreciated!

yes, indeed, while you’re inside a lua script, Orthanc is not able to process HTTP requests and therefore, if your python scripts is calling the Orthanc Rest API, it will end in a deadlock.

Since you’re already writing a python script, I would suggest that your python scripts runs standalone and regularly monitors the /changes uri. It will detect the OnStableSeries from the /changes and initiate the reaction on its own (-> no more lua script on your side).

Thanks for the reply! I will try this.

As an additional question: can Orthanc handle concurrent receiving? If two different scanners attempt to send to Orthanc at the same time, will one send fail? Can the two connections be queued in some way from the server side? Furthermore, will there be a conflict if new images are sent to Orthanc while python is using the rest API, or while the lua sendtoModality call is sending a processed scan to the PACS?

Thanks again.

As an additional question: can Orthanc handle concurrent receiving? If two different scanners attempt to send to Orthanc at the same time, will one send fail? Can the two connections be queued in some way from the server side? Furthermore, will there be a conflict if new images are sent to Orthanc while python is using the rest API, or while the lua sendtoModality call is sending a processed scan to the PACS?

Yes, Orthanc handles concurrent receiving of DICOM files, independently of the source of these files (DICOM, Lua, or REST).

Hello,

In such a complex workflow involving Lua-related deadlocks, is highly recommended to launch 2 instances of Orthanc on the same server:

  1. Orthanc “A” receives source DICOM from the scanner, and its Lua script invokes the processing script on the “OnStableSeries” event.
  2. Orthanc “B” receives modified DICOM files from the processing tool, and its Lua script forwards them to the PACS.
  3. Orthanc “A” makes HTTP POST calls to the “/instances” URI of Orthanc “B” through the Lua function “HttpPost()”.

Given that Orthanc is very lightweight, your server can run several instances of Orthanc without any problem.

HTH,
Sébastien-

PS: Replacing the Lua script by a Python script that monitors the “/changes” URI, as suggested by Alain, is nonetheless the best solution.