Open jkramar opened 7 years ago
I'm having trouble properly reproducing this behavior. From my attempts so far it seems that it is always working fine under python 3.
The freeze with python 01_hello_world -D
under python 2.7 seems to be connected to stdout capturing, and I'm still trying to find out what goes wrong (debugging the debugger is tricky...).
However doing ipdb 01_hello_world.py -d
works fine for me under both python 2 and python 3 and so does for example the classic python -m pdb 01_hello_world.py -d
ipython -i 01_hello_world.py -- -d
for me does run without the second error, but somehow yields scrambled symbols in the command prompt.
I'll dig further into the python 2.7 python 01_hello_world -D
problem. Meanwhile you could maybe try python 3, python -m pdb 01_hello_world.py -d
, or maybe updating ipdb
.
Hi Klaus,
Thanks for getting back!
When I look further into what happens if I do ipdb 01_hello_world.py -d , the problem occurs at utils.py:146, where tee_output() tries to os.dup2 ipython's stdout and stderr into some subprocesses, and ipython doesn't like that. However, python -m pdb 01_hello_world.py -d seems to work fine. :) Thanks for the tip!
Janos
On Tue, Jan 31, 2017 at 7:41 PM, Klaus Greff notifications@github.com wrote:
I'm having trouble properly reproducing this behavior. From my attempts so far it seems that it is always working fine under python 3. The freeze with python 01_hello_world -D under python 2.7 seems to be connected to stdout capturing, and I'm still trying to find out what goes wrong (debugging the debugger is tricky...).
However doing ipdb 01_hello_world.py -d works fine for me under both python 2 and python 3 and so does for example the classic python -m pdb 01_hello_world.py -d ipython -i 01_hello_world.py -- -d for me does run without the second error, but somehow yields scrambled symbols in the command prompt.
I'll dig further into the python 2.7 python 01_hello_world -D problem. Meanwhile you could maybe try python 3, python -m pdb 01_hello_world.py -d, or maybe updating ipdb.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/IDSIA/sacred/issues/134#issuecomment-276469458, or mute the thread https://github.com/notifications/unsubscribe-auth/AAxtDO__QrwSrQDEoZzD-XjsdxsFrO58ks5rX457gaJpZM4LvVu3 .
I've changed the tee_output to always properly tidy up the filedescriptors. For me that fixes the ipdb problems. See if it helps and reopen this issue if needed.
PS: This was a nasty one. Thanks for finding it!
I am having similar problems, but with pudb
.
What works for me is disabling the tee_output
entirely when self.unobserved
.
Wouldn't that be a good idea in any case?
Or are there reasons to capture the output when there's no chance of storing it anywhere anyway?
I have encountered an issue using ipdb.set_trace()
with FileStorageObserver
(possibly other observers, haven't tested that).
01_hello_world.py
works fine as-is.
If I modify it to include the observer, and include an ipdb.set_trace()
statement, as follows:
from __future__ import division, print_function, unicode_literals
from sacred import Experiment
from sacred.observers import FileStorageObserver
import ipdb
# Create an Experiment instance
ex = Experiment()
ex.observers.append(FileStorageObserver.create('my_runs'))
# This function should be executed so we are decorating it with @ex.automain
@ex.automain
def main():
print('Hello world!')
ipdb.set_trace()
... then when I do ipython 01_hello_world.py
I get this:
INFO - 01_hello_world - Running command 'main'
INFO - 01_hello_world - Started run with ID "63"
Hello world!
ERROR - 01_hello_world - Failed after 0:00:00!
Traceback (most recent calls WITHOUT Sacred internals):
File "redacted/01_hello_world.py", line 39, in main
ipdb.set_trace()
File "/Users/stephanie/anaconda3/lib/python3.6/site-packages/ipdb/__main__.py", line 67, in set_trace
p = _init_pdb(context).set_trace(frame)
File "/Users/stephanie/anaconda3/lib/python3.6/site-packages/ipdb/__main__.py", line 48, in _init_pdb
p = debugger_cls(def_colors, context=context)
File "/Users/stephanie/anaconda3/lib/python3.6/site-packages/IPython/terminal/debugger.py", line 17, in __init__
self.pt_init()
File "/Users/stephanie/anaconda3/lib/python3.6/site-packages/IPython/terminal/debugger.py", line 43, in pt_init
self.pt_cli = CommandLineInterface(self._pt_app, eventloop=self.shell._eventloop)
File "/Users/stephanie/anaconda3/lib/python3.6/site-packages/prompt_toolkit/interface.py", line 80, in __init__
self.output = output or create_output()
File "/Users/stephanie/anaconda3/lib/python3.6/site-packages/prompt_toolkit/shortcuts.py", line 124, in create_output
ansi_colors_only=ansi_colors_only, term=term)
File "/Users/stephanie/anaconda3/lib/python3.6/site-packages/prompt_toolkit/terminal/vt100_output.py", line 424, in from_pty
assert stdout.isatty()
AssertionError
---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
/Users/stephanie/anaconda3/lib/python3.6/site-packages/sacred/experiment.py in run_commandline(self, argv)
259 try:
--> 260 return self.run(cmd_name, config_updates, named_configs, {}, args)
261 except Exception:
/Users/stephanie/anaconda3/lib/python3.6/site-packages/sacred/experiment.py in run(self, command_name, config_updates, named_configs, meta_info, options)
208 meta_info, options)
--> 209 run()
210 return run
/Users/stephanie/anaconda3/lib/python3.6/site-packages/sacred/run.py in __call__(self, *args)
220 self._execute_pre_run_hooks()
--> 221 self.result = self.main_function(*args)
222 self._execute_post_run_hooks()
/Users/stephanie/anaconda3/lib/python3.6/site-packages/sacred/config/captured_function.py in captured_function(wrapped, instance, args, kwargs)
45 # =================== run actual function =================================
---> 46 result = wrapped(*args, **kwargs)
47 # =========================================================================
redacted/01_hello_world.py in main()
38 print('Hello world!')
---> 39 ipdb.set_trace()
/Users/stephanie/anaconda3/lib/python3.6/site-packages/ipdb/__main__.py in set_trace(frame, context)
66 frame = sys._getframe().f_back
---> 67 p = _init_pdb(context).set_trace(frame)
68 if p and hasattr(p, 'shell'):
/Users/stephanie/anaconda3/lib/python3.6/site-packages/ipdb/__main__.py in _init_pdb(context, commands)
47 try:
---> 48 p = debugger_cls(def_colors, context=context)
49 except TypeError:
/Users/stephanie/anaconda3/lib/python3.6/site-packages/IPython/terminal/debugger.py in __init__(self, *args, **kwargs)
16 self._ptcomp = None
---> 17 self.pt_init()
18
/Users/stephanie/anaconda3/lib/python3.6/site-packages/IPython/terminal/debugger.py in pt_init(self)
42 )
---> 43 self.pt_cli = CommandLineInterface(self._pt_app, eventloop=self.shell._eventloop)
44
/Users/stephanie/anaconda3/lib/python3.6/site-packages/prompt_toolkit/interface.py in __init__(self, application, eventloop, input, output)
79 # Inputs and outputs.
---> 80 self.output = output or create_output()
81 self.input = input or StdinInput(sys.stdin)
/Users/stephanie/anaconda3/lib/python3.6/site-packages/prompt_toolkit/shortcuts.py in create_output(stdout, true_color, ansi_colors_only)
123 stdout, true_color=true_color,
--> 124 ansi_colors_only=ansi_colors_only, term=term)
125
/Users/stephanie/anaconda3/lib/python3.6/site-packages/prompt_toolkit/terminal/vt100_output.py in from_pty(cls, stdout, true_color, ansi_colors_only, term)
423 """
--> 424 assert stdout.isatty()
425 def get_size():
AssertionError:
During handling of the above exception, another exception occurred:
NameError Traceback (most recent call last)
redacted/01_hello_world.py in <module>()
34
35 # This function should be executed so we are decorating it with @ex.automain
---> 36 @ex.automain
37 def main():
38 print('Hello world!')
/Users/stephanie/anaconda3/lib/python3.6/site-packages/sacred/experiment.py in automain(self, function)
135 'interactive mode. Use @ex.main instead.')
136
--> 137 self.run_commandline()
138 return captured
139
/Users/stephanie/anaconda3/lib/python3.6/site-packages/sacred/experiment.py in run_commandline(self, argv)
269 else:
270 print_filtered_stacktrace()
--> 271 exit(1)
272
273 def open_resource(self, filename, mode='r'):
NameError: name 'exit' is not defined
Other info: running this on macOS High Sierra 10.13.5, which is probably my problem, but I figured I'd report it anyway.
(also, hi Klaus!)
Hi Stephanie! thanks for reporting! And sorry for the long latency. I haven't found a good way yet to balance my internship, my personal life, and maintaining Sacred. :sweat_smile:
I can reproduce the problem on my Debian, so it is clearly not due to macOS. The problem is the stdout-capturing. For some reason the (default) file-descriptor based capturing causes trouble with debuggers. You can get around the problem by adding the -C sys
option to switch to purely-python based capturing. When debugging you should also always add the -d
flag to tell sacred to stop messing with exceptions.
I am reopening this issue to keep track of the problem with -C fd
and debuggers.
I'm having trouble using a debugger with sacred. For simplicity, I'm running
01_hello_world.py
but with an error thrown in in main().If I try
python 01_hello_world.py -D
, which is supposed to start a pdb client, then the following happens:(And at this point python takes input and outputs nothing until I kill it.)
If I instead
ipdb 01_hello_world.py -d
, I get the following error (after Ic
ontinue):Similarly, if I
ipython -i 01_hello_world.py -- -d
:What can I do to successfully debug my experiments?