Deadlock onstoredinstance callback

Hello everyone,
I am developing a web application that integrates with orthanc and I am having trouble with using a python script that fires on the event of recieving a new instance that notifies my web app of a new instance.

My web app runs an ai model and produces a new dicom file (if the ai output has findings) when it recieves the new instance and this is when the deadlock emerges because the new dicom file is sent to orthanc and thus fires the onstored instance again ( I knew this deadlock is mentioned in the docs ) and so I use a python thread to send the generated dicom to orthanc and this solves the problem but I am wondering if anyone has better ideas to mitigate this issue because I feel like this might be bad practice/design because using a thread for the generation task doesn’t allow me to check if what the thread returned in case an error happens or a problem occurs.

Thank you if you’ve made it this far and please give me any suggestions about how you would deal with this.

Hi,

In my opinion, using a thread is not a big concern but it means that your external web-service is in charge of recording the errors and possibly handle retries.

A common approach is to have Orthanc call a quick route of your external service that simply post a message in a queue like RabbitMQ (or have Orthanc write the message in the queue directly) and then have a thread pool that handles these messages asynchronously and that can use the message queue retries capabilities.

HTH,

Alain.