python3.x - How can python3 use multiple processes to write logs to the same log more safely?
某草草
某草草 2017-05-27 17:39:32
0
2
752

I am doing a schedule and need to use multi-threading to call up the stored procedure or SQL in the program and record the log, and record the execution information in the log. However, according to the information, logging is multi-process safe and multi-thread unsafe. Is there any way to write logs to the same log file in multiple threads? thank you all

某草草
某草草

reply all(2)
给我你的怀抱

It is recommended to use the producer-consumer model. The producer writes logs to the queue through multiple threads, and the consumer takes the logs from the queue and writes them into the log

小葫芦

Is it multi-process or multi-thread?

If there are multiple processes, it is recommended to write to stderr, and then the manager (such as systemd or supervisord) can write the file uniformly.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template