When my script sleeps for 50sec my IDE locks up which is very annoying. I cant switch tabs, look through my source, type code, etc. It happens in pylde and pyscripter, i havent tried other IDEs. What can i do to fix this? i'm actually doing
for i in range(0, timeInSeconds): time.sleep(1)
hoping the IDE will update once per second but it doesnt look that way. What can i do to fix this?
I'm assuming you are running your code from within the IDE?
Your IDE is probably blocking while running your code. Look for a setting of some sort which might control that behaviour, otherwise I think your only choice would be to change IDE. (Or, run your code from outside the IDE)
Can you configure to run your script externally? I don't know about the specific IDEs, but I would try to spawn a different process for the debugged script and not run them under the IDE. If that doesn't help, then it is a problem of the IDEs.
The problem is your IDE not python. I don't use sleep that often, I've just tried it on the Eric IDE and you can use your IDE while your code is running, and sleeping. If can't set your IDE to do so and you need it then consider to change IDE or to run your code from console.
Personally, I think you should never ever ever execute code in the same loop as your IDE. Since most IDEs run a GUI mainloop, blocking this will cause complete freeze of the user interface. It is just asking for trouble, and I would take out bug reports against both those IDEs.
I suspect the problem the IDE is sitting in a loop waiting for the script to finish.
That in itself is not a problem, provided any user generated messages are still processed while the IDE is in this loop.
But what I suspect is going wrong in this case is the IDE is just running the loop without processing and messages and hence the user interface appears to be locked.
The IDE would need to be changed to either process GUI messages while in the loop or alternatively it needs to create a thread to run the the script. The thread would then run in the background and the GUI would remain responsive.
For example the Zeus for Windows IDE uses the background thread approach and it does not have this problem.
Related
I'm using selenium to do some webdriver stuff and I'd like to pause / resume it at any time on input of the enter key while I'm running it in anaconda prompt.
I know you can use
input()
at a certain point to make it wait for you to input but I can't figure out how to make it so that anytime I input it pauses and then again input to resume.
Instead of trying to achieve this via Python changes, I'd suggest doing it through whatever command prompt / terminal you're using the run the script.
On Linux or Mac systems, you can press ctrl+Z in the terminal while your program is running to make it pause. Then you could type fg when you want to resume.
Sounds like you're using Windows, which is too bad because I don't know such an easy fix. I did a bit of Googling and saw some people talking about using "Process Explorer" to suspend processes, e.g. here, so you could try looking there if you want.
Anyway, I'll still leave this answer up because it could directly solve the problem for a future searcher who's running Linux or Max, but it seems like you might need to wait for help from someone with more Windows experience than me. Good luck :/
I'd like to keep my Python script running, even when my computer is sleeping.
I am using a Mac.
My file is only on my computer, not online.
I know of UptimeRobot, but I don't know how to configure that to my local file.
I would prefer to keep my file local, because it makes a lot of things easier for my project.
Is there anything that can help me achieve this? (not hardware, thanks.)
If you need more information, please leave a comment!
It's very simple.
open a terminal
type caffeinate
press Enter
Once you have done this, your Mac will stay awake for as long as you leave the Terminal running.
You can minimize or hide it, and your Mac will not go to sleep until you use the keyboard shortcut Ctrl+C to interrupt the command.
source
I'm making a drawing program with python and pygame. I am trying to incorporate a script-fu thing in which the program opens a python live interpreter upon startup and allows the user to execute commands in the interpreter alongside the graphical interface.
My current strategy is to run the main loop inside its own thread, then have the application opened using a bash script that does 'python -i main.py'
Is this a safe/effective/ideal way of doing this? How can I use locks to ensure that commands coming in from the interpreter are executed between main loop iterations?
This is my first time using threads, so please explain to me like I am 7.
Thanks :)
The interpreter won't cooperate with locks you set (since it doesn't know about them). Thus, you cannot guarantee when the code entered by the user will execute.
Consider using the code module to build your own interactive console (it's really easy!). Then you can do the locking every time you go to execute user input.
Why are you using a third party live interpreter? Do you realize that pygame comes with one built in? The documentation is here. This will eliminate all of your problems quite easily.
Seems that even after unchecking the option in the PyDev/Debug preferenecs pane to launch in the background, once it's launched I have to go to task manager to kill the python process.
As far as I can tell when working with Django you need to add runserver --noreload to your program argument in Run > Run... menu
This often happens when you're using something like cherrypy/django and the process restarts after you've changed a python file while it's running. When this happens, I think the process is different but still using the same output console and thus won't be killed when you press the red button.
I'm not sure there's a way of fixing it, except for disabling auto-restarting in the web framework etc.
I have a python script that uses plt.show() as it's last instruction. When it runs, IDLE just hangs after the last instruction. I get the image but I don't get the prompt back.
On other scripts I typically use ctrl-c to break the program (sometimes doesn't work immediately) but how do I get the prompt back with the plt.show()? Ctrl-c doesn't work...
Are there other ways to stop the program?
This is IDLE on Windows, if it makes any difference.
I have seen this problem with IDLE and matplotlib when using them on Windows. I don't know the exact cause, but Ctrl-c a couple times has typically worked for me. If that doesn't work for you, you can use the normal interpreter instead of write your plot directly to a file instead of the screen.
This is one of those (plentiful) times when IDLE doesn't behave like a normal Python script or interpreter session. Because of this, I usually avoid IDLE.
Ctrl+F6
(Restart shell)
or Shell->Restart Shell
When you use plt.show(), the python subprocess enters the GUI toolkit's event loop and blocks until the event loop exits. When it exits, you get the prompt back.
If you are using the TkAgg backend, you'll need to move your mouse over a figure after you press Ctrl+C. That will cause the event loop to stop. (Tkinter has its quirks)
Alternatively, IdleX offers Matplotlib support with IDLE using the EventLoop.py extension. You can display and interact with figures without using plt.show(). Just be sure to set plt.interactive(True) before generating figures.
I had same issue in Canopy Python Editor, and I was able to interrupt python session with CTRL+. ("dot" button). Hope that helps, or they probably do things in a similar ways