Exception 'signal only works in main thread' when Connection.run command with pty=True
See original GitHub issueDescribe the bug When running a command with Connection.run and argument pty=True in a thread we get that error. fabric version 2.7.0
To Reproduce Steps to reproduce the behaviour (please attach a minimal example): Running the code below on fabric 2.6.0 everything work fine, while if it is run with 2.7.0 it fails due to this line https://github.com/fabric/fabric/blob/8a9336963581df8d84cc91c4191d16fe1873b4ea/fabric/runners.py#L46
from fabric import Connection
import threading
def function(connection):
command="uptime"
connection.run(command, warn=True, pty=True, hide=False, timeout=None)
connection_kwargs = {
"host": <MY_IP>,
"user": <MY_USER>,
"forward_agent": False,
"connect_kwargs": {"key_filename": "<PATH TO MY KEY>"},
}
connection = Connection(**connection_kwargs)
command="uptime"
connection.run(command, warn=True, pty=True, hide=False, timeout=None)
t1=threading.Thread(target=function, args=(connection,))
t1.start()
t1.join()
Expected behaviour fabric works within a thread
Environment Bug seen in python 3.7.2 and 3.10.1
- What version of the Python interpreter are you using? Are you using an alternative interpreter such as PyPy?
- What operating system are you using both client & server-side? Ubuntu, centos and amazon linux as server and mac as client
- Are you using OpenSSH server or something else? OpenSSH
- Which version or versions of the software are you using?
- Have you already tried the latest release? yes
- Have you, or can you, try some older releases to pin down where the bug appeared? 2.6.0 work fine
- How can the developers recreate the bug on their end? If possible, include a copy of your code, the command you used to invoke it, and the full output of your run (if applicable.)
13:28:46 up 3 days, 20:17, 1 user, load average: 0.00, 0.00, 0.00
Exception in thread Thread-5 (function):
Traceback (most recent call last):
File "/Users/giordafr/.pyenv/versions/3.10.1/lib/python3.10/threading.py", line 1009, in _bootstrap_inner
self.run()
File "/Users/giordafr/.pyenv/versions/3.10.1/lib/python3.10/threading.py", line 946, in run
self._target(*self._args, **self._kwargs)
File "/tmp/test.py", line 5, in function
connection.run(command, warn=True, pty=True, hide=False, timeout=None)
File "<decorator-gen-3>", line 2, in run
File "/Users/giordafr/.pyenv/versions/parallel-cluster-tests/lib/python3.10/site-packages/fabric/connection.py", line 30, in opens
return method(self, *args, **kwargs)
File "/Users/giordafr/.pyenv/versions/parallel-cluster-tests/lib/python3.10/site-packages/fabric/connection.py", line 725, in run
return self._run(self._remote_runner(), command, **kwargs)
File "/Users/giordafr/.pyenv/versions/parallel-cluster-tests/lib/python3.10/site-packages/invoke/context.py", line 102, in _run
return runner.run(command, **kwargs)
File "/Users/giordafr/.pyenv/versions/parallel-cluster-tests/lib/python3.10/site-packages/fabric/runners.py", line 72, in run
return super(Remote, self).run(command, **kwargs)
File "/Users/giordafr/.pyenv/versions/parallel-cluster-tests/lib/python3.10/site-packages/invoke/runners.py", line 379, in run
return self._run_body(command, **kwargs)
File "/Users/giordafr/.pyenv/versions/parallel-cluster-tests/lib/python3.10/site-packages/invoke/runners.py", line 430, in _run_body
self.start(command, self.opts["shell"], self.env)
File "/Users/giordafr/.pyenv/versions/parallel-cluster-tests/lib/python3.10/site-packages/fabric/runners.py", line 46, in start
signal.signal(signal.SIGWINCH, self.handle_window_change)
File "/Users/giordafr/.pyenv/versions/3.10.1/lib/python3.10/signal.py", line 47, in signal
handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
ValueError: signal only works in main thread of the main interpreter
Issue Analytics
- State:
- Created a year ago
- Comments:5
Top Results From Across the Web
ValueError: signal only works in main thread - Stack Overflow
Python signal handlers are always executed in the main Python thread, even if the signal was received in another thread.
Read more >ValueError: signal only works in main thread of the main ...
The Anvil server runs on the main thread of a Python process. When it receives a new request, it processes it on another...
Read more >PyInvoke
1.7) works when Invoke is run in --complete mode, i.e. in tab-completion scripts. ... with the command string triggering that result.
Read more >ValueError('signal only works in main thread') - W&B Help
I'm running a hyper parameter sweep using PL and Weights and Biases's framework. Running on a GPU on Google Colab which causes all...
Read more >Fabric - Read the Docs
return c.run(command, hide=True).stdout.strip() ... Note: This feature only works with Paramiko 1.14.3 and above; if your Paramiko version ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
We are seeing a similar
signal only works in main thread
regression in behaviour in 2.7 when invoking.run
withFabric 2.6.0 worked without issue.
In both cases we were using python 3.8.
Fabric 2.7 has bugs, Fabric 2.6 works fine