How can I get the RUN button in Visual Studio Code to turn GREEN again?

In summary: I have tried exiting and opening it up, as well as restarting my computer. I also tried running everything on my other computer at work and the same thing happens.Hello again @pbuk :) . I seem to be having the same problem even in the command prompt (except for the fact that running the master file from the command prompt did not stop other python files from working in vscode). Below are pictures of what's going on. I called my make_worksheet function to make 12 copies of the "fractions intro" worksheet and name it "attempt 34". I typed python master.py in the command prompt and then tried viewing the generated latex file in vscode (should I not have
  • #1
SamRoss
Gold Member
254
36
TL;DR Summary
One python file seems to have broken itself and others
I have been using Visual Studio Code for a couple months now and it has been fine. When I want to run some code, there is usually a little green triangle button in the top right corner that I can click on. A few days ago, that triangle turned white only for Python files (it is still green for Latex files). I posted some pictures below.

It is also exhibiting strange behavior. The project I am working on involves creating multiple versions of math worksheets on various topics for my students. I have a bunch of latex worksheet templates and a "master" python file which reads the latex templates and then writes a new file with different numbers for each problem. Everything was working fine until recently. Now, when I run the master python file, it might work a couple times but eventually it stops working and clicking on the white run button does nothing.

When this happens, all other python files that I try opening stop working as well and my only recourse is to shut down Visual Studio Code and reopen it, hoping for another couple good runs before it all breaks again. Any ideas would be appreciated. I've already tried already restarting Visual Studio Code, restarting my computer, and uninstalling and reinstalling Visual Studio Code. I also tried running everything on my other computer at work and the same thing happens. Thank you!

Edit: I noticed something which might be a clue. I have a "make_worksheet" function which should generate as many versions of a worksheet as I want. After a couple run throughs with everything working, the bad attempt will always be bad in the same way. It will generate a few versions of the worksheet (not as many as I put in) and the last line of the latex file is always \newpage.
 

Attachments

  • white triangle.PNG
    white triangle.PNG
    20.3 KB · Views: 333
  • green triangle.PNG
    green triangle.PNG
    16.5 KB · Views: 319
Last edited:
Computer science news on Phys.org
  • #2
Here is something to try:

At the top of your code, add this line -- import sys
Add this as the last line -- sys.exit()

I believe that the reason the triangle doesn't turn green is that your Python script isn't returning control back to the operating system. By importing the sys module and calling its exit() method, that should signal VS Code that your program has finished.
 
  • #3
The obvious first question to ask, "Have you tried rebooting?"
 
  • Like
Likes phinds
  • #4
Hi @Mark44. Thanks for the help. Unfortunately I'm still seeing the same behavior. It ran a couple times then stopped. I noticed something which might be a clue. I have a "make_worksheet" function which should generate as many versions of a worksheet as I want. After a couple run throughs with everything working, the bad attempt will always be bad in the same way. It will generate a few versions of the worksheet (not as many as I put in) and the last line of the latex file is always \newpage.
 
  • #5
anorlunda said:
The obvious first question to ask, "Have you tried rebooting?"
I have, yes.
 
  • #6
The Python debugger in VS Code (or for that matter any IDE) is designed for debugging, not live runs against large datasets and/or spawning multiple external processes. I won't go into the technology of how VS Code does that (unless somebody asks really nicely :D), but in essence because of the way Python works it is a bit of a kludge.

So develop, test and debug your program using a couple of simple structures, and then when you are done do a test run with the full dataset from the command prompt with python master.py.
 
  • #7
pbuk said:
...do a test run with the full dataset from the command prompt with python master.py.
Hello again @pbuk :) . I seem to be having the same problem even in the command prompt (except for the fact that running the master file from the command prompt did not stop other python files from working in vscode). Below are pictures of what's going on. I called my make_worksheet function to make 12 copies of the "fractions intro" worksheet and name it "attempt 34". I typed python master.py in the command prompt and then tried viewing the generated latex file in vscode (should I not have done that?). As you might be able to make out from the third picture below if you squint hard enough, I got 2 versions of the worksheet as opposed to the requested 12. Again, the latex file stopped at a \newpage (every worksheet template ends with \newpage). It did not go any further than that and it did not pull my "template - end.tex" file which is just a .tex file that has \end{document} written on it which I need to complete the created attempt file.

I also noticed that in the command prompt, I am not able to enter any new commands unless I exit and open it up again.
 

Attachments

  • master pic.PNG
    master pic.PNG
    4.8 KB · Views: 185
  • command prompt.PNG
    command prompt.PNG
    3.4 KB · Views: 171
  • worksheet pic.PNG
    worksheet pic.PNG
    29.6 KB · Views: 175
  • #8
Sounds like in attempting to create 12 output files you are spawning 12 processes which are not terminating properly. Are you running tex2pdf or similar as part of this process?
 
  • #9
Am working on a fix in Photoshop.

Plz attach full-size uncompressed screenshot.

:woot:
 
  • #10
Also I notice that you are working on this in a Dropbox folder; that is probably not a good idea as Python will be competing with Dropbox for handles for the files. Probably best to do all development work in a folder that does not have any kind of live backup (or any backup at all - you are using git?)
 
  • #11
Mark44 said:
Here is something to try:

At the top of your code, add this line -- import sys
Add this as the last line -- sys.exit()

I believe that the reason the triangle doesn't turn green is that your Python script isn't returning control back to the operating system. By importing the sys module and calling its exit() method, that should signal VS Code that your program has finished.
No, you don't need sys.exit or anything else, a Python script terminates at the end of the file.
 
  • #12
pbuk said:
Sounds like in attempting to create 12 output files you are spawning 12 processes which are not terminating properly. Are you running tex2pdf or similar as part of this process?
No, I'm not. Should I be? Here are some pics of the make_worksheet function if it's helpful.
 

Attachments

  • Screenshot (1).png
    Screenshot (1).png
    32.6 KB · Views: 192
  • Screenshot (2).png
    Screenshot (2).png
    38.6 KB · Views: 165
  • Screenshot (3).png
    Screenshot (3).png
    37.8 KB · Views: 178
  • #13
DaveC426913 said:
Am working on a fix in Photoshop.

Plz attach full-size uncompressed screenshot.

:woot:
Thanks for the help, @DaveC426913. What exactly do you need a screenshot of?
 
Last edited by a moderator:
  • #14
pbuk said:
Also I notice that you are working on this in a Dropbox folder; that is probably not a good idea as Python will be competing with Dropbox for handles for the files. Probably best to do all development work in a folder that does not have any kind of live backup (or any backup at all - you are using git?)

I'm not using git. In fact, although I've heard it mentioned over and over, I'm not really quite sure what it is. I suppose my next step should be to look into it. Dropbox is where I've been keeping all my important files for many years. Guess I'll have to make a change.
 
  • #15
Dropbox (and Google Drive, MS OneDrive etc.) is fine for a typical document that you work on and save (or autosave) every few minutes. When you are developing software (not so much Python admittedly), the compiler and debugger may create many temporary files in your working directory. This confuses Dropbox.

SamRoss said:
Thanks for the help, #DaveC426913. What exactly do you need a screenshot of?
I think @DaveC426913 was trying to make a joke.

SamRoss said:
No, I'm not [spawning external processes]. Should I be? Here are some pics of the make_worksheet function if it's helpful.
No, you don't want to spawn tex2pdf processes in any big loops, that could only make things worse. You are opening and closing files a bit more than is ideal, but you do seem to be closing them properly and you are not running multiple copies of the program simultaneously so I can't see any obvious problem.

Oh unless your gen_times_tables etc. functions are causing some recursion? I assume these set the global variables which you then substitute in: this is horrible, as is the hard coding of variable names for substitution (you could replace all of this with functions that return a dict with the keys as the placeholder text and the values the text to substitute), and you don't need the up_to variable, you can just use the length() of the relevant dict.
 
  • Like
Likes SamRoss
  • #16
pbuk said:
Oh unless your gen_times_tables etc. functions are causing some recursion? I assume these set the global variables which you then substitute in: this is horrible, as is the hard coding of variable names for substitution (you could replace all of this with functions that return a dict with the keys as the placeholder text and the values the text to substitute), and you don't need the up_to variable, you can just use the length() of the relevant dict.

Yes, that is what I've been doing. I do have a heck of a lot of global variables which did seem awkward to me. I'll try the dictionary strategy and let you know how it goes.
 
  • Like
Likes pbuk

FAQ: How can I get the RUN button in Visual Studio Code to turn GREEN again?

How do I get the RUN button to turn GREEN in Visual Studio Code?

The RUN button in Visual Studio Code turns GREEN when the code is successfully compiled and executed. If it is not turning green, there could be a few reasons:

  • The code has errors or syntax issues that need to be fixed.
  • The necessary extensions or dependencies are not installed.
  • The code needs to be saved before it can be run.

Fixing any of these issues should make the RUN button turn GREEN again.

Why is the RUN button not turning GREEN in Visual Studio Code?

As mentioned before, the RUN button not turning GREEN may be due to errors in the code, missing dependencies, or not saving the code. It could also be due to insufficient memory or computer resources to run the code. Checking for these issues and addressing them should help resolve the problem.

What should I do if the RUN button is stuck on YELLOW or RED in Visual Studio Code?

If the RUN button is stuck on YELLOW or RED, it could mean that the code is still compiling or executing, or there is an infinite loop or error in the code. Wait for the process to finish or check for any errors in the code to fix the issue. If the problem persists, try restarting Visual Studio Code.

Is there a shortcut to make the RUN button turn GREEN in Visual Studio Code?

Yes, there is a keyboard shortcut to run code in Visual Studio Code. For Windows, it is Ctrl+Alt+N and for Mac, it is Cmd+Shift+D. This will automatically save and run the code, making the RUN button turn GREEN.

How can I change the color of the RUN button in Visual Studio Code?

The color of the RUN button in Visual Studio Code can be changed through the settings. Go to File > Preferences > Settings and search for "run button." From there, you can customize the color of the button to your preference.

Back
Top