0

We are having issues mixing threads and forks that is basically the same as described in this blog article: http://rachelbythebay.com/w/2011/06/07/forked/

(mixing threads and forks is causing some child processes to hang on a FUTEX call)

Her analysis is basically that their SSH libraries are creating all sorts of threads, and she concludes that they need to not use ssh

We need ssh, does anyone know of a python ssh library that does not spawn threads?

Cameron Sparr
  • 3,925
  • 2
  • 22
  • 31
  • What are you using at the moment? – Jon Clements Dec 05 '12 at 19:04
  • Umm, I only know of [paramiko](http://www.lag.net/paramiko/) and [fabric](http://docs.fabfile.org/en/1.5/) (which is good for admin tasks and stuff) - can't say I'm aware of their internals though – Jon Clements Dec 05 '12 at 19:12
  • Can't you invoke `ssh` using the `subprocess` module and running a command on the remote server through it? This way, you're not relying on any ssh libraries so you don't have to deal with threading. I don't know how complex your situation is, but that's what i would do. – Ehtesh Choudhury Dec 05 '12 at 19:25

1 Answers1

0

SSH is a quite complicated protocol that supports various things like port forwarding, X forwarding, tty stuff and more so it is unlikely that there are "simple" implementations.

As for multithreading, there is twisted.conch which has the downside of having to run a reactor, although it might be easier to integrate.

Another solution would be to do your SSH stuff in workers with python's multiprocessing package. These workers would not need to fork and would take units of work, do the necessary ssh stuff and report back the results.

mensi
  • 9,580
  • 2
  • 34
  • 43
  • The `multiprocessing` module does use `fork` on Unix, and also it does use threads, even though it depends on the task. If the OP wants to use a stdlib module than `subprocess` is the best choice I think. – Bakuriu Dec 05 '12 at 20:02
  • `multiprocessing` uses processes, not threads. This allows to isolate the app with forking logic from the multithreaded ssh library and communicate over pipes. – mensi Dec 05 '12 at 20:24
  • The `multiprocessing` module **does** use threads to deal with processes. Just check the code for the `Queue` or the `Pool` objects for example. If you want to have control over threads and processes you must use `subprocess`. – Bakuriu Dec 05 '12 at 21:18