redho home | products | services
Web Design Forums

Web Design Forums  


Web Hosting, Web Design, Software and Web Development Forums  
 FAQFAQ   MemberlistArchive  Log inLog in   RegisterRegister 
         

how to build a timeout in a function?



 
Post new topic   Reply to topic    Web Design Forums -> Python programming forum
View previous topic :: View next topic  
Author Message
Lusis Backwood JR



Joined: 26 May 2006
Posts: 87
Location: United States
Hello.
I'd like to build a timeout in a function. I tried this by doing a while loop and check the time for X difference. Of course, this took 100% of the processor. Are there better ways to create such feature?
  Reply with quote


Klimapol



Joined: 27 May 2006
Posts: 134
Depends on what else the function does.
  Reply with quote
amoralis



Joined: 22 Jun 2006
Posts: 21
Klimapol or what context your using the function in??
  Reply with quote
Lusis Backwood JR



Joined: 26 May 2006
Posts: 87
Location: United States
Klimapol, it fetches a tarball from the web
using httplib
  Reply with quote
Klimapol



Joined: 27 May 2006
Posts: 134
Lusis Backwood JR, And are you using any other framework or GUI or similar?
  Reply with quote
Lusis Backwood JR



Joined: 26 May 2006
Posts: 87
Location: United States
Klimapol, nope I do not
  Reply with quote
Klimapol



Joined: 27 May 2006
Posts: 134
And do you want to just abort if more than X seconds are used, or do you want to be called back every so often when data is fetched?
  Reply with quote
Lusis Backwood JR



Joined: 26 May 2006
Posts: 87
Location: United States
Klimapol, i'd like to abort it when it's exceeding X seconds of time
  Reply with quote
Klimapol



Joined: 27 May 2006
Posts: 134
If you just want to avoid stalling, the ideal way is to use e.g. twisted which lets you send off a request while doing other thing at the same time, i.e. you schedule the page to be fetched and schedule a timeout, and run the main loop
A low-tech solution is to use socket.setdefaulttimeout which lets you set a default timeout on socket operations
You can set the timeout per-socket too, but urllib doesn't expose the socket it uses AFAIK
Unfortunately that solution won't let you timeout on nameserver lookups.
An alternative is to run the fetching in a separate thread but then you can't really abort it if it takes more than the wanted amount of time
  Reply with quote
Page 1 of 1
Post new topic   Reply to topic    Web Design Forums -> Python programming forum


Dubai Forums - Expat Help | Vegan Chat | Java Programming | Free 3D tutorials and 3d textures | Paris Forum | EU Forum
Free Dubai Classifieds | Free London Classifieds | Jobs in London

High Quality, Custom 3d animation and Web Design solutions Royal Quality Web Hosting Services Vegetarian and Animal Rights news

Powered by phpBB © 2001, 2005 phpBB Group