Hi folks.
I am using a modified version of AutoClassify.py running as a service to write instances out to a share as they come in then delete them from Orthanc, but have had a few instances failing to export successfully.
In my most recent test of a scan containing four series of 11700 images, all arrived inside Orthanc, but the second and third series only exported 11699 instances and the fourth only exported 11698. The missing originals were left behind inside Orthanc and manually running the script exported them as expected.
Has anyone else encountered similar?
I was thinking of perhaps reducing the limit to 1 (not sure if this would make any difference whatsoever) or adding a time.sleep(0.1) after the r = statement below. Does this make any sense? Is there a better option?
As my use case is that I want ALL instances exported, is there a better way to code the loop to achieve this? This is my first stint of Python programming so advice tailored to Python-noob friendly would be appreciated
Sébastien, I also moved the DoDelete as below so that it won’t happen if the ClassifyInstance fails to write the instance to storage. It would be good if the example AutoClassify.py has the same change.
while True:
r = RestToolbox.DoGet(URL + ‘/changes’, {
‘since’ : current,
‘limit’ : 4 # Retrieve at most 4 changes at once
})
for change in r[‘Changes’]:
We are only interested interested in the arrival of new instances
if change[‘ChangeType’] == ‘NewInstance’:
try:
ClassifyInstance(change[‘ID’])
if args.remove:
RestToolbox.DoDelete(‘%s/
instances/%s’ % (URL, change[‘ID’])) # If requested, remove the instance once it has been copied - will not reach this section if it fails to write the file in the try above
except:
print(‘Unable to write instance %s to the disk’ % change[‘ID’])
current = r[‘Last’]
if r[‘Done’]:
print(‘.’, end=“”)
time.sleep(15)
Cheers,
Mark
HI folks.
I can confirm the changes I thought of first have made no difference. Resending the test scan resulted in 1 instance being skipped in the 3rd series and 10 in the 4th series.
Is there a better way to handle this - eg., is there a method that allows you to get the first image and send then delete that from orthanc, then find the now first image and send that infinitum?
Cheers,
Mark
Okay, this works:
while True:
r = RestToolbox.DoGet(URL + ‘/changes’, {
‘since’ : current,
‘limit’ : 4
})
for change in r[‘Changes’]:
if change[‘ChangeType’] == ‘NewInstance’:
try:
ClassifyInstance(change[‘ID’])
if args.remove:
RestToolbox.DoDelete(‘%s/instances/%s’ % (URL, change[‘ID’])) # If requested, remove the instance once it has been copied - will not reach this section if it fails to write the file in the try above MWH
except:
print(‘Unable to write instance %s to the disk’ % change[‘ID’])
current = r[‘Last’]
if r[‘Done’]:
print(‘.’, end=“”)
current = 0 # start at beginning again MWH
time.sleep(15)
The export log indicated that for some reason it failed to write instances out in some cases. Moving the RestToolbox.DoDelete inside the try statement so that it doesn’t delete the source file if a write failure occurs prevents the instance from being deleted from inside Orthanc, and having the current=0 in the if r[‘Done’]: section starts the export process at the start again after the 15 second delay. The skipped instances then exported correctly (confirmed the original source and the export location bit for bit using fc /B). It would be good to know if there was a race condition or something else causing this, but I’m happy with this workaround for now.
…
Unable to write instance c51bb84a-9c234090-abf79b4f-72d3e41e-d7f8b088 to the disk
Unable to write instance 69e25f47-f5853484-fd7b8c44-015e0c26-3e767a1c to the disk
Unable to write instance 001f3444-4ec2794f-ae382d18-9c0f5b59-742bc251 to the disk
Unable to write instance 70f8e755-87bb50cf-07faa112-339c4085-68ef4be0 to the disk
…
Cheers,
Mark
Hello Mark,
Thanks for the remark about the call to “DoDelete()”! I have just adapted the sample accordingly:
https://bitbucket.org/sjodogne/orthanc/commits/bec08e9236f5c33ee9ddd0a959abee579aab9bdf
Regarding the instruction “current = 0”, I prefer to keep the sample script unmodified, as other strategies might make sense in other situations than yours (such as simply restarting the Python script with the “–all” command-line option).
Regards,
Sébastien-