python exception like structure with a timer
I have a program that depends on being able to query a online database. If the internet connection fails, I want the program to continue, but with different parameters. I am currently using an exception like the following:
Code:
try: Is there a method I could use, to place my two lines of code, like an exception. The result would be if the commands did not finish executing in a set amount of time(say 20 seconds). a secondary clause would execute. for example: Code:
try: |
How about :-
import time x = time.time() #your code here y = time.time() if y > (x+20): do a else: do b I have not tested this but I think it should work. Let me know. |
Quote:
Code:
import time |
Quote:
I think the question was how to make the call to CDDB.query() take less time in case the connection fails. @shanenin I don't know about the CDDB-module, but did you look for some way in that module to specify the time-out? That would be the prefferred solution of course. If there's no such way, this might help: Code:
#!/usr/bin/env python |
That last code worked, thanks. :-)
|
All times are GMT -5. The time now is 02:54 PM. |