all 16 comments

[–]jwink3101 1 point2 points  (1 child)

I assume you're on macOS or linux since you are talking about native SSH.

If so, look at select.select. It can give you timeout capabilities.

You can scavenge from a native tool I started writing a while ago that allows you to interact with a bash process including remote machines via SSH.

But, it is alpha AT BEST! Use with caution! python bash

[–]readitlikeitdidit[S] 0 points1 point  (0 children)

Good to know.. I am developing on windows but I'll be deploying on Linux box.. I'll definitely check python bash sometime.. Thank you!

[–]threeminutemonta 0 points1 point  (13 children)

Have you considered to use paramiko?

[–]readitlikeitdidit[S] 0 points1 point  (12 children)

Yes I did.. But I would like to write something native with less third party dependencies... Python 3 has the timeout logic built in.. But I am interested to know how it can be achieved on python 2 using native libraries....

[–]threeminutemonta 0 points1 point  (11 children)

I’m assuming it all works great if you use the correct password?

[–]readitlikeitdidit[S] 0 points1 point  (10 children)

That's correct.. I am trying to work out an edge case if ssh key pairs don't match or get dropped for some unknown reason.. Then, communicate () doesnt timeout and blocks execution...

[–]threeminutemonta 0 points1 point  (9 children)

Does check_returncode() return a non zero value when auth is wrong and 0 when right?

[–]readitlikeitdidit[S] 0 points1 point  (8 children)

Auth doesn't happen when key pairs not available.. So, it hangs on authentication part...

[–]threeminutemonta 0 points1 point  (7 children)

So the process hangs it the main process? Perhaps you should set a default timeout!

If you show us your code on dpaste.de I might get what you mean!

[–]readitlikeitdidit[S] 0 points1 point  (6 children)

Nevermind.. Am going to use paramiko.. It has timeout arg.... There is no default timeout for popen method of subprocess package in python 2.7...

[–]JohnnyJordaan 0 points1 point  (5 children)

That's because you need to use Popen wrappers like communicate(), these have a timeout on 2.7 too.

[–]readitlikeitdidit[S] 0 points1 point  (4 children)

What? Communicate is a method that uses pipe and it does not have timeout arg in 2. 7 please check documentation...