annotate Sphinx/source/plugins/python/multiprocessing-1.py @ 842:92ca063536ed Orthanc-1.11.0

Orthanc 1.11.0
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 10 May 2022 10:50:15 +0200
parents 6e02cd89eb6a
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 math
6e02cd89eb6a moving python samples in separate files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 import orthanc
6e02cd89eb6a moving python samples in separate files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 import time
6e02cd89eb6a moving python samples in separate files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4
6e02cd89eb6a moving python samples in separate files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 # CPU-intensive computation taking about 4 seconds
6e02cd89eb6a moving python samples in separate files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 def SlowComputation():
6e02cd89eb6a moving python samples in separate files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 start = time.time()
6e02cd89eb6a moving python samples in separate files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 for i in range(1000):
6e02cd89eb6a moving python samples in separate files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 for j in range(30000):
6e02cd89eb6a moving python samples in separate files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 math.sqrt(float(j))
6e02cd89eb6a moving python samples in separate files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 end = time.time()
6e02cd89eb6a moving python samples in separate files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 duration = (end - start)
6e02cd89eb6a moving python samples in separate files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 return 'computation done in %.03f seconds\n' % duration
6e02cd89eb6a moving python samples in separate files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14
6e02cd89eb6a moving python samples in separate files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 def OnRest(output, uri, **request):
6e02cd89eb6a moving python samples in separate files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 answer = SlowComputation()
6e02cd89eb6a moving python samples in separate files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 output.AnswerBuffer(answer, 'text/plain')
6e02cd89eb6a moving python samples in separate files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18
6e02cd89eb6a moving python samples in separate files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 orthanc.RegisterRestCallback('/computation', OnRest)