0

I have some code that doesn't follow very good coding practices, which I've been asked to review and modify. It interfaces with another program, which it uses to setup and run simulations.

As it takes a very long time for the program to setup these simulations in memory (30m to 1h), every time I hit an un-handled exception in Python, it takes another 30-minutes to 1-hour for me to re-start from the beginning of the Python script.

Is there any way in Visual Studio Code//Python, to... 1) pause at an un-handled exception, then 2) correct the bad-line of code, and finally 3) continue execution (re-running that line)?

This would save me a tremendous amount of time. I understand it's probably not best practice, but deadlines are pretty tight on this one. Any ideas?

  • I don't know of an edit-and-continue for Python. A better solution is to save the memory state of the simulation program with pickle and reload the state if found, maybe allow a collection of states based on type of simulation – rioV8 Jun 06 '20 at 06:30
  • Ah, thanks, interesting idea! I wish I could use that in this case... The simulation program I'm using (DIgSILENT PowerFactory) links to the current instance of Python that's running though, so there's no way to save the entire state (including PowerFactory's state). In my case, I can't have the current Python instance close or it exits PowerFactory and I have to start from scratch. – Elliott Ventura Jun 08 '20 at 20:40

1 Answers1

1

You can catch uncaught exceptionss; it's a checkbox in the activity bar when the debugger is active: screenshot of the "Breakpoints" section of the debugger activity bar

With that you can potentially use "Jump to Cursor" to then go back to where you want to pick up execution again.

Brett Cannon
  • 14,438
  • 3
  • 45
  • 40