[Tutor] Running Python Scripts at same time

Peter Otten __peter__ at web.de
Sun Jun 28 11:42:13 EDT 2020


Mats Wichmann wrote:

> On June 26, 2020 4:21:02 AM MDT, John Weller <john at johnweller.co.uk>
> wrote:
>>I have a Python program which will be running 24/7 (I hope 😊).  It is
>>generating data in a file which I want to clean up overnight.  The way
>>I am looking at doing it is to run a separate program as a Cron job at
>>midnight – will that work?  The alternative is to add it to the loop
>>and check for the time. I have tried researching this but only got even
>>more confused.

> a common technique is a "log rotate" one... I see it's got a wikipedia
> page, take a look for some ideas.

You may also consider Python's logging library which supports log rotation:

https://docs.python.org/3/library/logging.handlers.html#timedrotatingfilehandler

That way you don't need the cronjob, or, if you want to do some 
postprocessing, can point it to the latest backup. Locking will become a 
non-issue.



More information about the Tutor mailing list