I have a python script which is constantly polling data. The script is constantly running and should never stop.
The script polls data from a track of keywords which are passed to it when the script is first run.
What would be the best way to update this track without stopping the script from another python script?
The only solution I can think of is to store the track in a txt file and check for any updates to the file on a set timer. Seems kind of messy.
It's better to encapsulate this settings file in a database. A simple SQLite DB file is enough - SQLite support is built-in with Python so no extra effort is required.
The advantage of a DB is that you won't run into race conditions of partially-written files, etc. The "configuration-adding" script adds keywords using a transaction, and the other script reading from the DB will only see it when it's wholly done. Just remember to not hold the DB open all the time in the periodic script. Once every some time, open it, read the keywords, and close it.
Polling a configuration-file is not messy, but a very common solution to this problem. You should go with it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With