How to have multi-threaded server log to one file ?

Alan Kennedy alanmk at hotmail.com
Wed Feb 27 04:40:54 EST 2002


shriek at gmx.co.uk (Stephen) wrote in message 
> When the server is run, each request from a client is handled by
> MyHandler() in a separate thread. If multiple requests are being run
> at the same time, how should I write my code so that they cal all
> write to the same log file without conflict ?  

How about representing every log message as a simple object which is
put() on a Queue.Queue? So each server thread produces messages to go
on the Queue, and a single logging thread consumes those messages and
does the actual writing into the log files. Since there is only ever
one thread writing to the files, there are no contention problems.

That Queue.Queue class is mightily useful!

Regards,

Alan.



More information about the Python-list mailing list