TestCenter Reference
Async.py
Go to the documentation of this file.
2# Copyright 2009, MeVis Medical Solutions AG
3#
4# The user may use this file in accordance with the license agreement provided with
5# the Software or, alternatively, in accordance with the terms contained in a
6# written agreement between the user and MeVis Medical Solutions AG.
7#
8# For further information use the contact form at https://www.mevislab.de/contact
9#
10
11
13
14# -- system imports ----------------------------------------------------------------------------{{{-
15# ----------------------------------------------------------------------------------------------}}}-
16
17# -- local imports -----------------------------------------------------------------------------{{{-
18import mevis
19from . import Base, Logging
20
21# ----------------------------------------------------------------------------------------------}}}-
22
23# -- global variables --------------------------------------------------------------------------{{{-
24
25gFinished = None
26# ----------------------------------------------------------------------------------------------}}}-
27
28
29# -- def waitForModules ------------------------------------------------------------------------{{{-
30
34def waitForModules(moduleList):
35 for module in moduleList:
36 waitForModule(module)
37
38
39# ----------------------------------------------------------------------------------------------}}}-
40
41
42# -- def waitForModule -------------------------------------------------------------------------{{{-
43
49def waitForModule(module):
50 global gFinished
51 context = Base.getTestCaseContext()
52
53 fldRunning = context.field("%s.taskRunning" % (module))
54 fldFinished = context.field("%s.taskFinished" % (module))
55
56 if not (fldRunning and fldFinished):
57 Logging.warning("Module %s has either no field taskFinished or no field taskRunning." % (module))
58 return
59
60 # Task not running.
61 if not fldRunning.value:
62 return
63
64 Logging.info("Waiting for module %s to finish processing its background task." % (module))
65
66 gFinished = False
67 fldListener = context.addFieldListener(fldFinished, "Async.setFinished", False)
68 while not gFinished:
69 mevis.MLAB.processEvents()
70 context.removeFieldListener(fldListener)
71
72
73# ----------------------------------------------------------------------------------------------}}}-
74
75
76# -- def setFinished # -------------------------------------------------------------------------{{{-
77
80 global gFinished
81 gFinished = True
82
83
84# ----------------------------------------------------------------------------------------------}}}-
waitForModules(moduleList)
Ask to wait for given modules to finish asynchronous processing.
Definition Async.py:34
waitForModule(module)
Method to wait for the given module to finish its task.
Definition Async.py:49
setFinished()
Set task to be finished.
Definition Async.py:79