简体   繁体   中英

Logging in multi-processing and multi-threading python program?

I am writing the back end of an Online Judge ( code checker) in python 2.7 which takes submissions from database(using mysql) evaluates the submission and writes the result back to database.I am running multi processes and each process runs multiple threads.For time being I am printing the evaluations status and other stuff directly to STDOUT. I haven't even put lock on printing(which is cumbersome because there are many print statements).Although I know lock is necessary in this condition.But initially my evaluator had only one process which had only one thread.I did not put lock that time and was redirecting STDOUT and STDERR to file from command line.But now the case is different.Also such log would difficult to be read and finding the error and other things if my evaluator crashes.Is there some neat way of logging in this case ??

You can use a variable like a counter that is a process or thread counter. So you can check this counter and you can use lock when counter bigger than 1.

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