Mercurial > hg > orthanc-book
diff Sphinx/source/plugins/python/multiprocessing-1.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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sphinx/source/plugins/python/multiprocessing-1.py Fri Jun 11 09:38:15 2021 +0200 @@ -0,0 +1,19 @@ +import math +import orthanc +import time + +# CPU-intensive computation taking about 4 seconds +def SlowComputation(): + start = time.time() + for i in range(1000): + for j in range(30000): + math.sqrt(float(j)) + end = time.time() + duration = (end - start) + return 'computation done in %.03f seconds\n' % duration + +def OnRest(output, uri, **request): + answer = SlowComputation() + output.AnswerBuffer(answer, 'text/plain') + +orthanc.RegisterRestCallback('/computation', OnRest)