-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Exception 'signal only works in main thread' when Connection.run command with pty=True #2204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Releated to: fabric/fabric#2204
Releated to: fabric/fabric#2204
Releated to: fabric/fabric#2204
Releated to: fabric/fabric#2204
Releated to: fabric/fabric#2204
Releated to: fabric/fabric#2204
Releated to: fabric/fabric#2204
Releated to: fabric/fabric#2204
Releated to: fabric/fabric#2204
Releated to: fabric/fabric#2204
Quite annoying bug, have to rollback from 2.7.0 on 2.6.0. |
Fabric 2.7 has bugs, |
We are seeing a similar
Fabric 2.6.0 worked without issue. In both cases we were using python 3.8. |
Hello, is there any update on a potential fix for this issue? Thank you! |
v2.7 likely contains bugs. [packages]
fabric = "==2.6"
[requires]
python_version = "3.9.9" |
Same issue on python 3.9 |
Weird that this is happening on Pythons before 3.9, since I dug into this and found https://docs.python.org/3.9/whatsnew/3.9.html containing a note about seemingly exactly this error message (just search for 'signal'). This likely started happening in Fabric 2.7 since that's when the SIGWINCH change using the signal library landed. Off the top of my head the right fix is probably to make that signal registration conditional on being the main thread; someone running Fabric inside worker threads is rather unlikely to care about highly interactive remote apps, which is what SIGWINCH is for. Side note: I have notes from internal users at my job that |
Hello, is there any update on the patch? |
I use fabric as a library, and was able to get around this by monkey patching the problematic part: from invoke.terminals import pty_size
from fabric.main import Argument, Config, Executor, Fab
def patched_start(self, command, shell, env, timeout=None):
self.channel = self.context.create_session()
if self.using_pty:
cols, rows = pty_size()
self.channel.get_pty(width=cols, height=rows)
# NOTE: Everything else is the same except for these two commented lines
# if hasattr(signal, "SIGWINCH"):
# signal.signal(signal.SIGWINCH, self.handle_window_change)
if env:
if self.inline_env:
parameters = " ".join(["{}={}".format(k, v) for k, v in sorted(env.items())])
command = "export {} && {}".format(parameters, command)
else:
self.channel.update_environment(env)
self.send_start_message(command)
class MyProgram(Fab):
def update_config(self):
# This lets us patch Remote.start with the function above
self.config.runners.remote.start = patched_start
super().update_config()
program = MyProgram(
name="Fabric",
version="1.0.0",
executor_class=Executor,
config_class=Config,
)
sys.exit(program.run()) |
Ran into this on CircleCI while fixing a related issue - it looks like the simple check of "are we the main thread?" is sufficient to avoid the problem. That fix will be released imminently in Fabric 3.2.2. |
Describe 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
fabric/fabric/runners.py
Line 46 in 8a93369
Expected behaviour
fabric works within a thread
Environment
Bug seen in python 3.7.2 and 3.10.1
alternative interpreter such as PyPy?
appeared? 2.6.0 work fine
copy of your code, the command you used to invoke it, and the full output of
your run (if applicable.)
The text was updated successfully, but these errors were encountered: