Mercurial > hg > orthanc-book
view Sphinx/source/plugins/python/multiprocessing-4.py @ 818:48676fb3ac0f
Added tag Orthanc-1.10.0 for changeset 01fa632daae9
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 23 Feb 2022 15:03:47 +0100 |
parents | 6e02cd89eb6a |
children |
line wrap: on
line source
import json import multiprocessing import orthanc import requests import signal TOKEN = orthanc.GenerateRestApiAuthorizationToken() def SlaveProcess(): r = requests.get('http://localhost:8042/instances', headers = { 'Authorization' : TOKEN }) return json.dumps(r.json()) def Initializer(): signal.signal(signal.SIGINT, signal.SIG_IGN) POOL = multiprocessing.Pool(4, initializer = Initializer) def OnRest(output, uri, **request): answer = POOL.apply(SlaveProcess) output.AnswerBuffer(answer, 'text/plain') orthanc.RegisterRestCallback('/computation', OnRest)