signal only works in main thread

1,746 views
Skip to first unread message

RVince

unread,
Jul 25, 2011, 10:28:23 AM7/25/11
to pylons-discuss
I have a pylons project where, from within my controller, I am
instantiating an SSH client class using this class:

http://www.goldb.org/sshpython.html

With the following code:

sSHController = SSHController('xxx', 'root', 'password', '#')
sSHController.login()

Whereupon, at login(), it fails with a :

ValueError: signal only works in main thread

>> self.archive()
Module edigate.controllers.eligibility:730 in archive view
<< def archive(self):
sSHController = SSHController('xxx', 'root',
'password', '#')
sSHController.login()
>> sSHController.login()
Module edigate.controllers.SSHController:41 in login view
<<
"""
self.ssh = pyssh.Ssh(self.user_name, self.host_name,
self.port)
self.ssh.login(self.password)
>> self.ssh = pyssh.Ssh(self.user_name, self.host_name, self.port)
Module pyssh:106 in __init__ view
<< self.sshpid = 0 # perhaps merge this with isopen
self.old_handler = signal.getsignal(signal.SIGCHLD)
sig_handler = signal.signal(signal.SIGCHLD,
self.sig_handler)

def __del__(self):
>> sig_handler = signal.signal(signal.SIGCHLD, self.sig_handler)

I'm at a complete loss here. Can someone please point me in the right
direction to solving this? Perhaps this belongs in comp.lang.python,
not sure, thought I would start by looking in this group. Thanks,
RVince

Tim Hoffman

unread,
Jul 25, 2011, 8:40:32 PM7/25/11
to pylons-...@googlegroups.com
Hi

Its a fundamental (at least for cpython) artifact of signals and threads that  only the main thread can set signal masks/recieve signals.

Your probably running in a threaded server and a child thread is trying to utilise the ssh client lib  which is trying to set a signal mask, hence the error.

I would suggest your strategy as currently planned won't work.

Alternate strategies might be to 

* run the ssh client in a subprocess connected via a pipe  (not sure what/how you plan to communicate over the ssh channel, so not sure if this will work for you).
* look at alternate servers that don't use threads (may be twisted) though this is a guess.
* look at an alternate implementation of ssh that doesn't set signal masks (don't know if one exists)

Rgds

Tim

Michael Merickel

unread,
Jul 28, 2011, 1:43:34 PM7/28/11
to pylons-...@googlegroups.com
You may also be able to run the ssh client within a multiprocessing process that you can spawn from the thread. I can't promise that works, but it shouldn't be difficult to try out.


--

Michael
Reply all
Reply to author
Forward
0 new messages