简体   繁体   中英

String not in code getting written into a file

I'm having a really mysterious behaviour with a relatively simple piece of python3 code. I hope someone can point me in the right direction.

Context

I have a script and a module with some functions I've writen. Lets call them script.py and functions.py . General purpose of the code is not really relevant at this point, I think.

One of the functions defined in functions.py and used in script.py is called write_log . It is a really simple function with two arguments: a file's full path and a string. The function opens the file, appends the text and closes again the file. So:

write_log('/my/dir/log.txt', 'This a normal string')

Will simple append the string to the file.

Problem

Since script.py is executed many times through cron, I use write_log often to log some details about the execution and check them later. In a certain point in time, I had a line like this in my code:

write_log('/my/dir/log.txt', 'Writing intermediate files.')

Everything was running as expected. Until I took out the line.

The text 'Writing intermediate files.' keeps getting appended in my log file even though the text is not anywhere in the code. I've searched it both in the full length of script.py and functions.py and 'Writing intermediate files' isn't written in any of the files. It is important to make clear it can't come from any external source either because of the nature of the script.

Confused about this, I used write_log to mark several, lets say, "checkpoints" in the code to pinpoint the exact line of code where the mystery string is written into the file, and, to my surprise, it happens in this line:

time.sleep(1)

Which doesn't make any sense to me. What is going on?

Check active processes and cron jobs. I suspect that your old code is still running in a process and produces the unexpected log entries.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM