annotate Sphinx/source/plugins/python/multiprocessing-3.py @ 702:6e02cd89eb6a

moving python samples in separate files
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 11 Jun 2021 09:38:15 +0200
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
702
6e02cd89eb6a moving python samples in separate files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 import pydicom
6e02cd89eb6a moving python samples in separate files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 import io
6e02cd89eb6a moving python samples in separate files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3
6e02cd89eb6a moving python samples in separate files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 def OffloadedDicomParsing(dicom):
6e02cd89eb6a moving python samples in separate files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 # No access to the "orthanc" library here, as we are in the slave process
6e02cd89eb6a moving python samples in separate files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 dataset = pydicom.dcmread(io.BytesIO(dicom))
6e02cd89eb6a moving python samples in separate files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 return str(dataset)
6e02cd89eb6a moving python samples in separate files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8
6e02cd89eb6a moving python samples in separate files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 def OnRest(output, uri, **request):
6e02cd89eb6a moving python samples in separate files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 # The call to "orthanc.RestApiGet()" is only possible in the master process
6e02cd89eb6a moving python samples in separate files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 dicom = orthanc.RestApiGet('/instances/19816330-cb02e1cf-df3a8fe8-bf510623-ccefe9f5/file')
6e02cd89eb6a moving python samples in separate files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 answer = POOL.apply(OffloadedDicomParsing, args = (dicom, ))
6e02cd89eb6a moving python samples in separate files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 output.AnswerBuffer(answer, 'text/plain')