DEV Community

Aitor
Aitor

Posted on

Script freezes when losing focus

This is a how to stop freezing when your CMD loses focus.

 Ok, so i was doing a Python script that downloads a backup using requests, it is a CLI program, and i am using Microsoft Windows as main operating system. I noticed that when my CMD window loses focus, the script freezes, so i did a little research and found This answer in superuser exchange, it was really useful, but yet, it kinda give me the impression that the script still freezes, since i was using requests, and updating the screen everytime a chunk of file was downloaded, i realized that indeed, the script still freezes, in "mi caso" this is what i did to solve it.

  • Disable QuickEdit mode (See that superuser answer)
  • Use the threading module in order to make a threading request.

For the threading part, check This answer from stackoverflow, you can use thread.join() in order to wait for the thread to finish if you need to.

  Anyways, this is all you need to do if you want to unfreeze your script when your CMD windows loses focus.

Top comments (0)