views:

337

answers:

2

I was thinking of using the logging module to log all events to one file. The number of threads should be constant from start to finish, but if one thread fails, I'd like to just log that and continue on. What's a simple way of accomplishing this? Thanks!

+4  A: 

Not entirely sure what you mean by "one thread fails", but if by "fail" you mean that an exception propagates all the way up to the top function of the thread, then you can wrap every thread's top function (e.g. in a decorator) to catch any exception, log whatever you wish, and re-raise. The logging module should ensure thread-safety of logging actions without further precautions being needed on your part on that score.

Alex Martelli
A: 

Mybe this can help

Ib33X
No, that post refers to logging from multiple *processes*, not threads. And for that, also look at http://docs.python.org/dev/library/logging.html#logging-to-a-single-file-from-multiple-processes
Vinay Sajip