示例#1
0
def runBehavior_BM( strBehavior, nTimeOut = 60 ):
    "launch a behavior on Nao, return "" if loading failed, or the 'naoqi' name of the behavior"
    "nTimeOut: temps maximum a attendre en secondes, -1 => pas d'attente (don't wait end)"
    abm = naoqitools.myGetProxy( "ALBehaviorManager" );
    strBeName = getLibraryName( strBehavior );
    
    # comme on ne peut le charger qu'une fois, on doit toujours le stopper avant (ca stoppera un précédent)
    try:
        print( "naolibrary.runBehavior: stopping previously running (%s)" % strBehavior );
        abm.stopBehavior( strBeName );
    except:
        pass # not previously running ... not a big deal
    try:
        print( "naolibrary.runBehavior: unloading previously loaded (%s)" % strBehavior );
        abm.unloadBehavior( self.strBehaviorName );
    except:
        pass # not previously running ... not a big deal
    
    try:
        print( "naolibrary.runBehavior: loading (%s)" % strBehavior );
        abm.loadBehavior( strBeName );
    except:
        print( "naolibrary.runBehavior: can't preload behavior, version >= 1.4.32 (%s) ?" % strBehavior );
    try:
        print( "naolibrary.runBehavior: running (%s)" % strBehavior );
        abm.runBehavior( strBeName );
        rStep = 0.2;
        rTotal = 0;
        while( abm.isBehaviorRunning( strBeName ) or rTotal > nTimeOut ):
            print( "naolibrary.runBehavior: waiting '%s'... %f..." % ( strBehavior, rStep ) );
            time.sleep( rStep );
            rTotal += rStep;
    except BaseException, err:
        debug.logToChoregraphe( "naolibrary.runBehavior: error occurs: " + str( err ) );
        strBeName = "";
示例#2
0
    def run( self ):
        import debug # import the module in the children thread
        debug.debug( "evaltools.ASyncEvalThread evaluating '%s'" % self.strPythonCode );
        self.bMustStop = False;
        sys.settrace( self.globaltrace ); # permit to kill thread, WRN: it's a debug purpose functionnality not existing or all platform and ...
        #~ self.strPythonCode = """
#~ import signal
#~ print( 'installing handler...' );
#~ def handler(signum, frame):
    #~ print 'Signal handler called with signal', signum;
    #~ exit( 42 );
#~ signal.signal(signal.SIGTERM, handler)
#~ """ + self.strPythonCode; => ERROR signal only works in main thread
        if( config.bDebugMode ):
            debug.logToChoregraphe( "ASyncEvalThread: strPythonCode: '%s'" % self.strPythonCode );
        exec( self.strPythonCode, self.globaldico, self.localdico ); # TODO: here: do something to test bMustStop is not Set to True, if so exit
        debug.debug( "altools: ASyncEvalThread evaluating '%s' - end" % ( self.strPythonCode ));