timer for a function

Steven D'Aprano steven at REMOVE.THIS.cybersource.com.au
Mon Feb 8 20:36:48 EST 2010


On Fri, 05 Feb 2010 18:23:09 +0100, mk wrote:

[...]
> On paramiko mailing list I got the suggestion to build a timer and then
> quit this by myself:
> 
>> The timeout option in connect() is for the socket, not for the entire
>> operation. You are connected, so that timeout is no longer relevant.
>> You would probably have to wrap the transport.connect() method in a
>> timer to break out of this early.
> 
> Question: how can I do that? Use another threaded class? Is there some
> other way?

I don't use threads enough (or at all) to answer that question directly, 
but I can point you at these. Hopefully they will help, or at least give 
you some ideas:

http://code.activestate.com/recipes/534115/
http://code.activestate.com/recipes/473878/

Found by googling for "python timeout any function".



> Additional snag is SSHClient() is a class that internally uses threads.
> How do I kill brutally its threads? Is there any way to do it?

You can't kill threads in Python. You have to ask them nicely to die.

Google on "python kill thread" for more.




-- 
Steven



More information about the Python-list mailing list