Staredit Network

Staredit Network -> Computers and Technical -> Timeout (Python)
Report, edit, etc...Posted by DT_Battlekruser on 2006-02-17 at 00:31:47
Is there a command in Python that lets you say If <code> takes more than x seconds, break?
Report, edit, etc...Posted by Doodle77(MM) on 2006-02-17 at 16:03:53
I think the module `signal' does something like this. Look it up in the python help file.
Report, edit, etc...Posted by CheeZe on 2006-02-17 at 16:46:04
CODE

import time

limit = 10 #Or some other number that you want it to stop.

a = time.time()

while time.time()-a < limit:
#Actions to take


If you need the try and except, then I assume you can just put it in the loop?
Report, edit, etc...Posted by Doodle77(MM) on 2006-02-17 at 17:01:04
No I think he belives it will hang on a certain command (such as raw_input) but he needs to break after a bit.
Report, edit, etc...Posted by DT_Battlekruser on 2006-02-17 at 20:14:42
Yeah, it's an individual command. In this case it's a HTTPSocket GET command, but the essence is it's one command that takes time.

I'll look into the signal module a bit later; I've got to run right now.
Next Page (1)