nengo / nengo-gui

Nengo interactive visualizer
Other
99 stars 38 forks source link

GUI doesn't load if code contains pdb.set_trace() #622

Open ikajic opened 8 years ago

ikajic commented 8 years ago

If pdb.set_trace() appears in the code, as in:

import nengo
import pdb

with nengo.Network('net') as model:
    print(1)
    pdb.set_trace()

the browser hangs with loading. I've tried with: Chromium Version 46.0.2490.71 Built on 8.2 Mozilla Iceweasel 38.4.0

rsimmons1 commented 8 years ago

Reproduced the issue in firefox and wrote a selenium test for it. When the issue is fixed the test will update to passed.

jgosmann commented 8 years ago

Isn't this kind of expected? You're basically stopping the script and dropping into the debug prompt, aren't you?

Seanny123 commented 8 years ago

I agree with Jan. What's the alternative behaviour?

ikajic commented 8 years ago

What happens when your code contains "pdb.set_trace" (I recommend trying if you haven't done so) is that your browser gets stuck in "Loading" mode. If you already haven't loaded the GUI, it won't be loaded at all. Currently, to a user this could appear as the GUI is not working, which is wrong.

There are several options:

These are just a few things that come to my mind, but it would be helpful to inform a user about the reason why the GUI is not being loaded.

On 15 February 2016 at 21:57, Sean Aubin notifications@github.com wrote:

I agree with Jan. What's the alternative behaviour?

— Reply to this email directly or view it on GitHub https://github.com/nengo/nengo_gui/issues/622#issuecomment-184490239.

jgosmann commented 8 years ago

I am against a special handle of pdb.set_trace because there is a more general, or actually two more general problems.

  1. We don't provide interactivity. Script output isn't displayed and there is no way to provide interactive input.
  2. We don't handle non-terminating programs (or programs that need very long to terminate).

pdb.set_trace is one way to encounter these problems, but there is a near-infinite number of other ways (and we can't handle each one specifically).

As a partial solution I would propose the following:

  1. Execute the model script in a separate thread (or process) if we're not already doing this. Update the GUI asynchronously once the execution finishes. That should handle that the GUI isn't loading at all.
  2. For long running scripts show some kind of warning? Allow to cancel execution?
  3. Interactive console? (This one needs some thought how to handle this in the best way. There might not be a good way to do that.)

There's one thing to check though: I'm not completely sure about the effect of pdb.set_trace. I would not be surprised if it halts all threads of the Python instance in which case point 1. would not help (except when using a separate process, but that complicates things because of interprocess communication).