I doubt that, I believe subprocess is the way to go. Just kick it in, sleep for 
some time and poll it, increment a counter and sleep again....

To call a function from a script with timeout, create a new python script as a 
thin wrapper around the function and send the timeout via command line (use 
subprocess)

If you are writing the function you can set a timeout and increment the counter 
inside the function...

Any one has a better idea???

    MaxWait = <time in seconds>
    KillTries = 5
    ##smbProc is a unix command  invoked by subprocess.popen
    ##this can be a wrapper script around your function
    #Wait on the subprocess to be terminated on its own
    #If this does not happen within MaxWait time, kill it
    while smbProc.poll() == None:
        if MaxWait > 0: #Wait and poll at an interval of 1/2 seconds
            time.sleep(0.5)
            MaxWait -= 0.5
        elif KillTries >0: #Time's up, kill the subprocess and log the 
information
            KillTries -= 1
            print smbProc.send_signal(subprocess.signal.SIGTERM)
            time.sleep(0.50)
        else: #Extremely unlikely that this will ever be executed
            print "Unable to kill the process for 'FIVE' consecutive times"


Thanks,
Varun

-----Original Message-----
From: [email protected] 
[mailto:[email protected]] On Behalf Of 
pacopyc
Sent: Wednesday, April 07, 2010 6:54 PM
To: [email protected]
Subject: [python-win32] timeout function

Hi, I'm trying to execute a function that could end never (infinite 
time). I'd like to set a timeout. If function respond before 30 sec ok, 
else go away.
Can I do it? I can't find simple examples. Can you help me?

Thank you
_______________________________________________
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32
_______________________________________________
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to