X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FKERNEL_PY%2Fkernel%2Fthreadhelper.py;h=b6d6b06893aa6b493df798b9fd8510fa5cd918a4;hb=dac5e4d5c8f771e0cedb7caa5292bc54be5ca89a;hp=d1fa76a69b52510c0b0402e751361d17d61e0ccb;hpb=288dc1c84630e521220d796b7c88c518f34856d5;p=modules%2Fkernel.git diff --git a/src/KERNEL_PY/kernel/threadhelper.py b/src/KERNEL_PY/kernel/threadhelper.py index d1fa76a69..b6d6b0689 100644 --- a/src/KERNEL_PY/kernel/threadhelper.py +++ b/src/KERNEL_PY/kernel/threadhelper.py @@ -1,5 +1,5 @@ # -*- coding: iso-8859-1 -*- -# Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE +# Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE # # 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 -# 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 @@ -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(). """ - print "##################### threadhelper.run" + print("##################### threadhelper.run") 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() @@ -107,15 +107,15 @@ class Runner(threading.Thread): return try: self._observer.processNotification() - except AttributeError, att: + except AttributeError as att: 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: - 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 @@ -232,14 +232,14 @@ class PeriodicTimer( threading.Thread ): 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(): - print "FINI" + print("FINI") def TEST_PeriodicTimer(): periodicTimer=PeriodicTimer(1,0,testIfContinue, endedAction) @@ -251,43 +251,43 @@ def function_ok(nbsteps=5): """ Fonction qui se termine correctement """ - print "D�but" + print("D�but") cnt=0 while ( cnt < nbsteps ): - print "Etape ", cnt + print("Etape ", cnt) time.sleep(0.6) cnt+=1 - print "Fin" + print("Fin") def function_with_exception(): """ Fonction qui aboutie � une lev�e d'exception """ - print "D�but" + print("D�but") 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") - 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. """ - print "D�but" + print("D�but") cnt=0 while ( 1 ): - print "Etape ", cnt + print("Etape ", cnt) time.sleep(1) cnt+=1 raise Exception("erreur") - print "Fin" + print("Fin") 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. """ - print "###########" + print("###########") 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: - 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: - print "La fonction s'est termin�e correctement" + print("La fonction s'est termin�e correctement") 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. """ - 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) - 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: - 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: - 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) @@ -354,7 +354,7 @@ def TEST_Runner(): def myCallbackFunction(): - print "myCallbackFunction: the job is ended" + print("myCallbackFunction: the job is ended") def TEST_runWithCallback(): @@ -366,17 +366,17 @@ def TEST_runWithCallback(): 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() ): - 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__": - import unittester + from . import unittester #TEST_PeriodicTimer() #TEST_Runner() #TEST_Timeout()