timer for a function

M

mk

I have the following situation:

1.

self.conobj = paramiko.SSHClient()

self.conobj.connect(self.ip, username=self.username,
key_filename=self.sshprivkey, port=self.port, timeout=opts.timeout)

2. very slow SSH host that is hanging for 30+ seconds on key exchange.

The timeout in the options regards only a socket timeout, not further
stages of connection negotiation, so it doesn't work there.

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?


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?

Regards,
mk
 
S

Steven D'Aprano

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

[...]
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.
 
A

Aahz

self.conobj = paramiko.SSHClient()

self.conobj.connect(self.ip, username=self.username,
key_filename=self.sshprivkey, port=self.port, timeout=opts.timeout)

2. very slow SSH host that is hanging for 30+ seconds on key exchange.

The timeout in the options regards only a socket timeout, not further
stages of connection negotiation, so it doesn't work there.

Does paramiko offer any kind of callback? In a similar situation with
pycurl, I built my own timer into a callback.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,109
Latest member
JanieMalco
Top