Salome HOME
projects
/
modules
/
kernel.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
[EDF30382] : Synchro mecanism to ease test of extreme situations
[modules/kernel.git]
/
src
/
KERNEL_PY
/
kernel
/
threadhelper.py
diff --git
a/src/KERNEL_PY/kernel/threadhelper.py
b/src/KERNEL_PY/kernel/threadhelper.py
index d1fa76a69b52510c0b0402e751361d17d61e0ccb..ff981def7102062aa42c2a229eecda14cbffda5c 100644
(file)
--- a/
src/KERNEL_PY/kernel/threadhelper.py
+++ b/
src/KERNEL_PY/kernel/threadhelper.py
@@
-1,5
+1,5
@@
# -*- coding: iso-8859-1 -*-
# -*- coding: iso-8859-1 -*-
-# Copyright (C) 2007-20
12 CEA/DEN, EDF R&D
, OPEN CASCADE
+# Copyright (C) 2007-20
24 CEA, EDF
, OPEN CASCADE
#
# Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
#
# Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@
-7,7
+7,7
@@
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
-# version 2.1 of the License.
+# version 2.1 of the License
, or (at your option) any later version
.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
@@
-88,12
+88,12
@@
class Runner(threading.Thread):
Ex�cution de la fonction. Impl�mentation de la m�thode run
d�clench�e par l'appel � Thread.start().
"""
Ex�cution de la fonction. Impl�mentation de la m�thode run
d�clench�e par l'appel � Thread.start().
"""
- print
"##################### threadhelper.run"
+ print
("##################### threadhelper.run")
if self._function is None: return
try:
self._return = self._function(*self._argv)
if self._function is None: return
try:
self._return = self._function(*self._argv)
- except Exception
,
e:
- print
e
+ except Exception
as
e:
+ print
(e)
self._exception = e
self._stopevent.set()
self.notifyObserver()
self._exception = e
self._stopevent.set()
self.notifyObserver()
@@
-107,15
+107,15
@@
class Runner(threading.Thread):
return
try:
self._observer.processNotification()
return
try:
self._observer.processNotification()
- except AttributeError
,
att:
+ except AttributeError
as
att:
if str(att) == "processNotification":
if str(att) == "processNotification":
- print
"L'observateur n'impl�mente pas la m�thode processNotification()"
+ print
("L'observateur n'impl�mente pas la m�thode processNotification()")
else:
else:
- print
"La fonction processNotification() a lev� une exception:"
- print
att
- except Exception
,
e:
- print
"La fonction processNotification() a lev� une exception:"
- print
e
+ print
("La fonction processNotification() a lev� une exception:")
+ print
(att)
+ except Exception
as
e:
+ print
("La fonction processNotification() a lev� une exception:")
+ print
(e)
def callback(self):
if self._callbackFunction is None: return
def callback(self):
if self._callbackFunction is None: return
@@
-232,14
+232,14
@@
class PeriodicTimer( threading.Thread ):
import os
testfilename="/tmp/threadhelperTestFile"
def testIfContinue():
import os
testfilename="/tmp/threadhelperTestFile"
def testIfContinue():
- print
"On examine la pr�sence du fichier ", testfilename
+ print
("On examine la pr�sence du fichier ", testfilename)
if os.path.exists(testfilename):
return STOP
else:
return CONTINUE
def endedAction():
if os.path.exists(testfilename):
return STOP
else:
return CONTINUE
def endedAction():
- print
"FINI"
+ print
("FINI")
def TEST_PeriodicTimer():
periodicTimer=PeriodicTimer(1,0,testIfContinue, endedAction)
def TEST_PeriodicTimer():
periodicTimer=PeriodicTimer(1,0,testIfContinue, endedAction)
@@
-251,43
+251,43
@@
def function_ok(nbsteps=5):
"""
Fonction qui se termine correctement
"""
"""
Fonction qui se termine correctement
"""
- print
"D�but"
+ print
("D�but")
cnt=0
while ( cnt < nbsteps ):
cnt=0
while ( cnt < nbsteps ):
- print
"Etape ", cnt
+ print
("Etape ", cnt)
time.sleep(0.6)
cnt+=1
time.sleep(0.6)
cnt+=1
- print
"Fin"
+ print
("Fin")
def function_with_exception():
"""
Fonction qui aboutie � une lev�e d'exception
"""
def function_with_exception():
"""
Fonction qui aboutie � une lev�e d'exception
"""
- print
"D�but"
+ print
("D�but")
cnt=0
while ( cnt < 5 ):
cnt=0
while ( cnt < 5 ):
- print
"Etape ", cnt
+ print
("Etape ", cnt)
time.sleep(1)
cnt+=1
raise Exception("erreur d'ex�cution de la fonction")
time.sleep(1)
cnt+=1
raise Exception("erreur d'ex�cution de la fonction")
- print
"Fin"
+ print
("Fin")
def infinite_function():
"""
fonction de dur�e infinie (tant qu'il y a du courant �l�ctrique) pour
le test du timeout.
"""
def infinite_function():
"""
fonction de dur�e infinie (tant qu'il y a du courant �l�ctrique) pour
le test du timeout.
"""
- print
"D�but"
+ print
("D�but")
cnt=0
while ( 1 ):
cnt=0
while ( 1 ):
- print
"Etape ", cnt
+ print
("Etape ", cnt)
time.sleep(1)
cnt+=1
raise Exception("erreur")
time.sleep(1)
cnt+=1
raise Exception("erreur")
- print
"Fin"
+ print
("Fin")
def runWithRunner(functionToRun):
def runWithRunner(functionToRun):
@@
-295,21
+295,21
@@
def runWithRunner(functionToRun):
Ex�cute la fonction avec le runner. On illustre ici la modalit�
d'utilisation du Runner.
"""
Ex�cute la fonction avec le runner. On illustre ici la modalit�
d'utilisation du Runner.
"""
- print
"###########"
+ print
("###########")
runner = Runner(functionToRun)
runner.start()
while ( not runner.isEnded() ):
runner = Runner(functionToRun)
runner.start()
while ( not runner.isEnded() ):
- print
"La fonction est en cours"
+ print
("La fonction est en cours")
time.sleep(0.2)
e = runner.getException()
if e is not None:
time.sleep(0.2)
e = runner.getException()
if e is not None:
- print
"La fonction s'est termin�e en erreur"
- print
e
+ print
("La fonction s'est termin�e en erreur")
+ print
(e)
# On peut en fait la relancer
# raise e
else:
# On peut en fait la relancer
# raise e
else:
- print
"La fonction s'est termin�e correctement"
+ print
("La fonction s'est termin�e correctement")
def runWithTimeout(functionToRun, timeout=10):
def runWithTimeout(functionToRun, timeout=10):
@@
-317,26
+317,26
@@
def runWithTimeout(functionToRun, timeout=10):
Ex�cute la fonction avec le runner. On illustre ici la modalit�
d'utilisation du Runner.
"""
Ex�cute la fonction avec le runner. On illustre ici la modalit�
d'utilisation du Runner.
"""
- print
"runWithTimeout : DEBUT"
+ print
("runWithTimeout : DEBUT")
runner = Runner(functionToRun)
runner.start()
# On se fixe un temps au del� duquel on consid�re que la fonction
# est en erreur => on tue le thread (timeout)
runner.wait(timeout)
runner = Runner(functionToRun)
runner.start()
# On se fixe un temps au del� duquel on consid�re que la fonction
# est en erreur => on tue le thread (timeout)
runner.wait(timeout)
- print
"Apr�s runner.timeout(timeout)"
+ print
("Apr�s runner.timeout(timeout)")
if not runner.isEnded():
runner.kill()
e = runner.getException()
if e is not None:
if not runner.isEnded():
runner.kill()
e = runner.getException()
if e is not None:
- print
"La fonction s'est termin�e en erreur"
- print
e
+ print
("La fonction s'est termin�e en erreur")
+ print
(e)
# On peut en fait la relancer
# raise e
else:
# On peut en fait la relancer
# raise e
else:
- print
"La fonction s'est termin�e correctement"
+ print
("La fonction s'est termin�e correctement")
- print
"runWithTimeout : FIN"
+ print
("runWithTimeout : FIN")
import sys
sys.exit(0)
import sys
sys.exit(0)
@@
-354,7
+354,7
@@
def TEST_Runner():
def myCallbackFunction():
def myCallbackFunction():
- print
"myCallbackFunction: the job is ended"
+ print
("myCallbackFunction: the job is ended")
def TEST_runWithCallback():
def TEST_runWithCallback():
@@
-366,17
+366,17
@@
def TEST_runWithCallback():
return False
runnerId = runner.getId()
return False
runnerId = runner.getId()
- print
"A runner has been started with id="+str(runnerId
)
+ print
("A runner has been started with id="+str(runnerId)
)
cpt = 0
while ( not runner.isEnded() ):
cpt = 0
while ( not runner.isEnded() ):
- print
"Waiting notification from process "+str(runner.getId())+", step n°"+str(cpt
)
+ print
("Waiting notification from process "+str(runner.getId())+", step n°"+str(cpt)
)
time.sleep(0.2)
cpt+=1
return True
if __name__ == "__main__":
time.sleep(0.2)
cpt+=1
return True
if __name__ == "__main__":
- import unittester
+
from .
import unittester
#TEST_PeriodicTimer()
#TEST_Runner()
#TEST_Timeout()
#TEST_PeriodicTimer()
#TEST_Runner()
#TEST_Timeout()