In Python docs, I found that logging messages are possible in python scripts that use the multiprocessing module to create different processes.
import multiprocessing import logging logger = multiprocessing.log_to_stderr() logger.setLevel(logging.INFO)
So logger.warning('doomed') will give me the message 'doomed' , but only to the console.
logger.warning('doomed')
'doomed'
How can I switch log messages to a file?
Multiprocessing logging is not trivial, but it is not complicated. You will need the logging module.
logging
The main thing is that the listener process receives all registration records through multiprocessor queues . This listener process then processes these entries using any internal handlers that you decide to use. In your case, you can use FileHandler or similar.
FileHandler
If you are in Python version 3.2 or later, you will have QueueHandler and QueueListener in the standard library. Quelistener is a listener process that I talked about before (yes, it has a start() method).
QueueHandler
QueueListener
Quelistener
start()
If you are in a previous version of Python, look at the link that basically shows how to rewrite them (and how to use them).
If you need links from an official document, see Writing to a single file from several processes from the Log section.
You may also be interested in this answer from the question How should I register when using multiprocessing in Python?
Source: https://habr.com/ru/post/1402890/More articles:IntelliJ increases heap scale space - heapEncoding error in JavaScript resource in Rails - ruby-on-railsRuby example to access google shopping api using GAN publisher ID - ruby โโ| fooobar.comFilter by id for multiple data in Django - pythonXPATH - how to select this part of the text? - phpThe jQuery popup menu disappears when the mouse is jqueryEmbedding ApplicationContext in Wicket component with @SpringBean fails - javaHow to focus on the first cell of a newly added row in dojox.grid.DataGrid - dojoIs array access better with a numeric or associative key? - performanceReading standard output from slaves using ipcluster - pythonAll Articles