1

This seems like a very simple question but I cannot find an answer to it anywhere on Stack Overflow.

I am running a script where some lines take a lot of time. If I stop a function later on in the script by pressing "Ctrl + C", VSC quits Python. So, I have to run those lines again, which is a pain.

To illustrate, let's say I ran 20 lines and have the variables associated with those lines in memory. I start running line 21, and would like to stop that line from running yet I would like to keep Python open so that I have the variables from the first 20 lines in memory.

I am wondering if there is a way to stop a function but not quit Python in Visual Studio Code. Thank you!

Kaan Yolsever
  • 242
  • 2
  • 13
  • 1
    Are you asking how you can keep the results of the lines that take a lot of time for the next time you run the script, without having to run them again? – mkrieger1 May 29 '21 at 22:33
  • @mkrieger1 yes exactly, say I ran 20 lines, and I am running the line 21. I would like to keep the memory intact (keep the variables from the first 20 lines) and stop the execution of line 21. Sorry if that was not clear – Kaan Yolsever May 29 '21 at 22:35
  • 1
    Why do you stop line 21 and do not leave it running? – mkrieger1 May 29 '21 at 22:44
  • @mkrieger1 let's say it's taking too long – Kaan Yolsever May 29 '21 at 22:46
  • 1
    Does this answer your question? [Saving the state of a program to allow it to be resumed](https://stackoverflow.com/questions/5568904/saving-the-state-of-a-program-to-allow-it-to-be-resumed) – mkrieger1 May 29 '21 at 22:52
  • @mkrieger1 Thank you but not really. I would like to know a way to stop executing a function without quitting Python in VSC. This is similar to keyboard interrupt when you are running Python in terminal. However, in VSC, Ctrl + C seems to kill the python instance along with the function – Kaan Yolsever May 29 '21 at 22:56

0 Answers0