I have a script that I sometime use in a Python Plug-in that is like shown below.
The first part in bold does some logging, so disregard that for now. The rest of it actually creates the archive, but then packages it up with some other files (A version of the Radiant Viewer in this case). On the server, it takes maybe 20-30 seconds to create the archive for a moderate-sized study, and it seems that maybe some other systems that access Orthanc ‘pause’ or timeout for a bit sometimes when that is happening. I have a few other similar scripts that take awhile as well, so if I can do the same with those that might solve some issues I have when there are intensive tasks running in my Python Plug-in while either the modalities are sending images or the RIS is making API calls to Orthanc.
So, I’m wondering if there is a way to ‘off-load’ that or ‘delegate’ that to a slave process on a UNIX system as described here:
https://book.orthanc-server.com/plugins/python.html?highlight=python#performance-and-concurrency
or if that even applies with the current releases.
Also, my dev systems use Mac OS running Docker Desktop, but the production systems run Debian / UBUNTU, but I am using the same Docker packages for both.
def OnDownloadStudyArchive(output, uri, **request):
host = “Not Defined”
userprofilejwt = “Not Defined”
if “headers” in request and “host” in request[‘headers’]:
host = request[‘headers’][‘host’]
if “headers” in request and “userprofilejwt” in request[‘headers’]:
userprofilejwt = request[‘headers’][‘userprofilejwt’]
logging.info(“STUDY|DOWNLOAD_ARCHIVE|ID=” + request[‘groups’][0] + " HOST=" + host + " PROFILE= " + userprofilejwt)
new_zip = BytesIO()
archive = orthanc.RestApiGet(uri)
with ZipFile(‘/python/radiant_cd.zip’, ‘r’) as radiant_zip:
with ZipFile(new_zip, ‘w’) as new_archive:
for item in radiant_zip.filelist:
To get rid of ‘__MACOSX’ files skip them here
if ‘__MACOSX’ not in item.filename:
logging.info(“Adding " +item.filename+ " to archive”)
new_archive.writestr(item, radiant_zip.read(item.filename))
else:
logging.info("Skipping " +item.filename+ “, it is a Mac OS file remnant.”)
new_archive.writestr(‘dcmdata.zip’, archive)
Important to read as binary, otherwise the codec fails.
f = open(“/python/ReadMe.pdf”, “rb”)
new_archive.writestr(‘ReadMe.pdf’, f.read())
f.close()
output.AnswerBuffer(new_zip.getvalue(), ‘application/zip’)
Stephen D. Scotti