timer for a function

Stephen Hansen apt.shansen at gmail.com
Mon Feb 8 21:44:17 EST 2010


On Fri, Feb 5, 2010 at 9:23 AM, mk <mrkafk at gmail.com> 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?
>

What OS? Does this have to be OS-independant? Are you using more then one
transport/SSLClient in your process and you want to just kill one (and any
of its child threads), or are you doing one per process?

If you want to terminate -all- threads your process is running in a given
timeframe, using a SIGALRM in the signal module will do it, I believe--
provided you don't need to support windows. I had a contextlib manager do
that for awhile. If you only want to terminate one (and its
child-threads)... you're out of luck, I think. The only way to terminate a
thread in Python is with conditions/events/whatever and the thread
cooperating and exiting on its own.

--S
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100208/2a1daa57/attachment-0001.html>


More information about the Python-list mailing list