PEP 282: A Logging System

Aahz aahz at pythoncraft.com
Fri Apr 12 09:41:12 EDT 2002


In article <2e37dc1.0204120001.11ee98b0 at posting.google.com>,
Vinay Sajip <vinay_sajip at yahoo.co.uk> wrote:
>aahz at pythoncraft.com (Aahz) wrote in message news:<a95c7k$801$1 at panix1.panix.com>...
>>
>> Your main difficulty with thread safety is WRT I/O.  How do you plan to
>> handle that?
>
>I/O is the province of the handlers, and I expect to make them
>thread-safe with respect to the underlying I/O through the use of
>thread locks. Of course this applies only to the handlers I provide as
>part of the distribution; user-defined handlers will need to make
>their own provision.

Yup.  You might want to work on some metaclass hacking or something that
permits locks to be automatically applied, or perhaps checks for a
locking API on registered handlers.

>The code released up till now does not have any locking at all.
>Empirically, a simple test harness I put together (just to see how the
>current code does) seems to run fine (eyeball-wise) on Python
>2.1.1/Windows and Python 1.5.2/Windows and Linux, though with 1.5.2 I
>had to remove calls to inspect. The test was logging to a FileHandler
>and a DatagramHandler. I was a little surprised at first not to see
>any problems, might this be due to the GIL? I don't know enough in
>detail about how the GIL works, but given that these handlers all work
>through C objects I would expect the GIL to play a role.

Yup.  Generally speaking, if you're making one-and-only-one I/O call in
your handler, you're mostly safe.  But don't count on it.

Your code looks fine to an eyeball test.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"I disrespectfully agree."  --SJM



More information about the Python-list mailing list