Question

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?

Was it helpful?

Solution

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)

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top