TestCenter Reference
Async.py
Go to the documentation of this file.
1 #
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 -----------------------------------------------------------------------------{{{-
18 import mevis
19 from . import Base, Logging
20 # ----------------------------------------------------------------------------------------------}}}-
21 
22 # -- global variables --------------------------------------------------------------------------{{{-
23 
24 gFinished = None
25 # ----------------------------------------------------------------------------------------------}}}-
26 
27 # -- def waitForModules ------------------------------------------------------------------------{{{-
28 
32 def waitForModules (moduleList):
33  for module in moduleList:
34  waitForModule(module)
35 # ----------------------------------------------------------------------------------------------}}}-
36 
37 # -- def waitForModule -------------------------------------------------------------------------{{{-
38 
44 def waitForModule (module):
45  global gFinished
46  context = Base.getTestCaseContext()
47 
48  fldRunning = context.field("%s.taskRunning" % (module))
49  fldFinished = context.field("%s.taskFinished" % (module))
50 
51  if not (fldRunning and fldFinished):
52  Logging.warning("Module %s has either no field taskFinished or no field taskRunning." % (module))
53  return
54 
55  # Task not running.
56  if not fldRunning.value:
57  return
58 
59  Logging.info("Waiting for module %s to finish processing its background task." % (module))
60 
61  gFinished = False
62  fldListener = context.addFieldListener(fldFinished, "Async.setFinished", False)
63  while not gFinished:
64  mevis.MLAB.processEvents()
65  context.removeFieldListener(fldListener)
66 # ----------------------------------------------------------------------------------------------}}}-
67 
68 # -- def setFinished # -------------------------------------------------------------------------{{{-
69 
71 def setFinished ():
72  global gFinished
73  gFinished = True
74 # ----------------------------------------------------------------------------------------------}}}-
75 
def waitForModules(moduleList)
Ask to wait for given modules to finish asynchronous processing.
Definition: Async.py:32
def waitForModule(module)
Method to wait for the given module to finish its task.
Definition: Async.py:44
def setFinished()
Set task to be finished.
Definition: Async.py:71