I wrote a small script that opens a window using PyQt when a specific file gets created.
This is to let me know when another program (that I have no control over) has finished calculating something. I know at the end of the calculation a specific file is created.
Here is the code:
from PyQt5.QtWidgets import QWidget, QLabel import os.path file_to_check = "D:/test.txt" alert_widget = QWidget() alert_widget.setWindowTitle("Program X finished") done_label = QLabel("Done",alert_widget) done_label.move(50,50) file_does_not_exist = True while file_does_not_exist: if os.path.isfile(file_to_check): file_does_not_exist = False alert_widget.show()
The widget that gets shown luckily just pops up in front of whatever window im currently active in, whether it's browsing the internet or working on an excel sheet. That is intended behaviour, but I did not write it in by specifying it as a "top level" window or somehting.
The script is started in an IPython console in Spyder and just left to run there. It works exactly as expected.
Now my questions
- is this constantly running loop good practice?
- are there any downsides to having that loop constantly running in the background?
- could it block other programs?
- is there another, more elegant way to achieve what I'm looking to do?
- is the code following python coding conventions?