madbg
madbg copied to clipboard
PermissionError: [Errno 1] Operation not permitted
When connecting with madbg client, the script dies and return with this error.
Stack trace:
File ".../site-packages/madbg/api.py", line 57, in sigio_handler
debugger, debugger_exit_stack = use_context(RemoteIPythonDebugger.start_from_new_connection(sock))
File ".../site-packages/madbg/utils.py", line 34, in use_context
context_value = exit_stack.enter_context(context_manager)
File "/usr/lib/python3.8/contextlib.py", line 425, in enter_context
result = _cm_type.__enter__(cm)
File "/usr/lib/python3.8/contextlib.py", line 113, in __enter__
return next(self.gen)
File ".../site-packages/madbg/debugger.py", line 170, in start_from_new_connection
with cls.start(sock.fileno()) as debugger:
File "/usr/lib/python3.8/contextlib.py", line 113, in __enter__
return next(self.gen)
File ".../site-packages/madbg/debugger.py", line 133, in start
pty.make_ctty()
File ".../site-packages/madbg/tty_utils.py", line 120, in make_ctty
detach_current_ctty()
File ".../site-packages/madbg/tty_utils.py", line 85, in detach_current_ctty
make_session_leader()
File ".../site-packages/madbg/tty_utils.py", line 33, in make_session_leader
os.setsid()
PermissionError: [Errno 1] Operation not permitted
I wrote a simple test:
import os
if __name__ == '__main__':
try:
os.setsid()
except OSError as e:
print(f"os.setsid failed: {e}")
print(f"pid={os.getpid()} pgid={os.getpgid(0)}")
Result:
os.setsid failed: [Errno 1] Operation not permitted
pid=132918 pgid=132918
Why does this happen and how do I resolve this?
Hey @chinghwayu, thank you for isolating the problem and opening an issue 😄 I'm in the process of preparing a new version for madbg that will also make setsid
unnecessary. In the meantime we could try to fix this issue.
I haven't seen this before, it would help if you could provide a few more details:
- On what distribution of linux are you running?
- How are you running the test script (and are you using a privileged user?)
- How are you running madbg?
- This is on Ubuntu 20.04. Doesn't occur on Redhat 7.7.
- normal user
import madbg
madbg.set_trace_on_connect()
and then in another window
$ madbg connect
And how do you run the python script? Just python script.py
in a shell?
And how do you run the python script? Just
python script.py
in a shell?
Yes
I have the exact same issue. madbg
kills my process when doing simply madbg attach <pid>
, where
on 0: Process Process-1:
Traceback (most recent call last):
File "/datadrive1/radu/envs/volt/lib/python3.10/multiprocessing/process.py", line 315, in _bootstrap
self.run()
File "/datadrive1/radu/envs/volt/lib/python3.10/site-packages/clearml/binding/environ_bind.py", line 168, in _patched_process_run
return PatchOsFork._original_process_run(self, *args, **kwargs)
File "/datadrive1/radu/envs/volt/lib/python3.10/multiprocessing/process.py", line 108, in run
self._target(*self._args, **self._kwargs)
File "/datadrive1/radu/envs/volt/lib/python3.10/site-packages/torch/utils/data/_utils/worker.py", line 269, in _worker_loop
r = index_queue.get(timeout=MP_STATUS_CHECK_INTERVAL)
File "/datadrive1/radu/envs/volt/lib/python3.10/multiprocessing/queues.py", line 113, in get
if not self._poll(timeout):
File "/datadrive1/radu/envs/volt/lib/python3.10/multiprocessing/connection.py", line 262, in poll
return self._poll(timeout)
File "/datadrive1/radu/envs/volt/lib/python3.10/multiprocessing/connection.py", line 429, in _poll
r = wait([self], timeout)
File "/datadrive1/radu/envs/volt/lib/python3.10/multiprocessing/connection.py", line 936, in wait
ready = selector.select(timeout)
File "/datadrive1/radu/envs/volt/lib/python3.10/selectors.py", line 416, in select
fd_event_list = self._selector.poll(timeout)
File "<string>", line 1, in <lambda>
File "/datadrive1/radu/envs/volt/lib/python3.10/site-packages/madbg/api.py", line 41, in set_trace
debugger, exit_stack = use_context(RemoteIPythonDebugger.connect_and_start(ip, port))
File "/datadrive1/radu/envs/volt/lib/python3.10/site-packages/madbg/utils.py", line 34, in use_context
context_value = exit_stack.enter_context(context_manager)
File "/datadrive1/radu/envs/volt/lib/python3.10/contextlib.py", line 492, in enter_context
result = _cm_type.__enter__(cm)
File "/datadrive1/radu/envs/volt/lib/python3.10/contextlib.py", line 135, in __enter__
return next(self.gen)
File "/datadrive1/radu/envs/volt/lib/python3.10/site-packages/madbg/debugger.py", line 170, in start_from_new_connection
with cls.start(sock.fileno()) as debugger:
File "/datadrive1/radu/envs/volt/lib/python3.10/contextlib.py", line 135, in __enter__
return next(self.gen)
File "/datadrive1/radu/envs/volt/lib/python3.10/site-packages/madbg/debugger.py", line 139, in start
instance = cls(slave_reader, slave_writer, term_type)
File "/datadrive1/radu/envs/volt/lib/python3.10/site-packages/madbg/debugger.py", line 46, in __init__
super().__init__(pt_session_options=dict(input=term_input, output=term_output), stdin=stdin, stdout=stdout)
File "/datadrive1/radu/envs/volt/lib/python3.10/site-packages/IPython/terminal/debugger.py", line 32, in __init__
Pdb.__init__(self, *args, **kwargs)
File "/datadrive1/radu/envs/volt/lib/python3.10/site-packages/IPython/core/debugger.py", line 237, in __init__
self.shell = TerminalInteractiveShell.instance()
File "/datadrive1/radu/envs/volt/lib/python3.10/site-packages/traitlets/config/configurable.py", line 551, in instance
inst = cls(*args, **kwargs)
File "/datadrive1/radu/envs/volt/lib/python3.10/site-packages/IPython/terminal/interactiveshell.py", line 653, in __init__
self.init_prompt_toolkit_cli()
File "/datadrive1/radu/envs/volt/lib/python3.10/site-packages/IPython/terminal/interactiveshell.py", line 450, in init_prompt_toolkit_cli
self.pt_app = PromptSession(
File "/datadrive1/radu/envs/volt/lib/python3.10/site-packages/prompt_toolkit/shortcuts/prompt.py", line 476, in __init__
self.app = self._create_application(editing_mode, erase_when_done)
File "/datadrive1/radu/envs/volt/lib/python3.10/site-packages/prompt_toolkit/shortcuts/prompt.py", line 727, in _create_application
application: Application[_T] = Application(
File "/datadrive1/radu/envs/volt/lib/python3.10/site-packages/prompt_toolkit/application/application.py", line 282, in __init__
self.output = output or session.output
File "/datadrive1/radu/envs/volt/lib/python3.10/site-packages/prompt_toolkit/application/current.py", line 71, in output
self._output = create_output()
File "/datadrive1/radu/envs/volt/lib/python3.10/site-packages/prompt_toolkit/output/defaults.py", line 95, in create_output
return Vt100_Output.from_pty(
File "/datadrive1/radu/envs/volt/lib/python3.10/site-packages/prompt_toolkit/output/vt100.py", line 467, in from_pty
fd = stdout.fileno()
AttributeError: 'types.SimpleNamespace' object has no attribute 'fileno'