comparison Sphinx/source/plugins/python/multiprocessing-4.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
comparison
equal deleted inserted replaced
701:f093160dd7f4 702:6e02cd89eb6a
1 import json
2 import multiprocessing
3 import orthanc
4 import requests
5 import signal
6
7 TOKEN = orthanc.GenerateRestApiAuthorizationToken()
8
9 def SlaveProcess():
10 r = requests.get('http://localhost:8042/instances',
11 headers = { 'Authorization' : TOKEN })
12 return json.dumps(r.json())
13
14 def Initializer():
15 signal.signal(signal.SIGINT, signal.SIG_IGN)
16
17 POOL = multiprocessing.Pool(4, initializer = Initializer)
18
19 def OnRest(output, uri, **request):
20 answer = POOL.apply(SlaveProcess)
21 output.AnswerBuffer(answer, 'text/plain')
22
23 orthanc.RegisterRestCallback('/computation', OnRest)