Re: logging module -- better timestamp accuracy on Windows

2011-02-16 Thread benhoyt
> For example, are you assuming that your clock() call in logging is > the very first call made? Yes, we were making that assumption (the time.clock() call in the import of our log module), which was true in our code, but I can see where it's not a good thing to assume generally. > Also, IIUC

Re: logging module -- better timestamp accuracy on Windows

2011-02-16 Thread benhoyt
> AFAIK, the Windows performance counter has long-term accuracy issues, > so neither is perfect. Preferably we should have a timer with the long- > term accuracy of time.time and the short-term accuracy of time.clock. Thanks for the tip -- yes, I hadn't thought about that, but you're right, Quer

Re: logging module -- better timestamp accuracy on Windows

2011-02-16 Thread benhoyt
> A simpler solution would be to caclulate the time it takes to the handle > the request using time.clock() and include it in the log message. > Something like: Thanks, Ross. Actually, we are doing exactly that already -- it's how we noticed the timestamp issue in the first place. However, that

logging module -- better timestamp accuracy on Windows

2011-02-15 Thread benhoyt
The Python logging module calls time.time() in LogRecord.__init__ to fetch the timestamp of the log record. However, time.time() isn't particularly accurate on Windows. We're logging start and end of our requests in our web server, which can be milliseconds apart, and the log timestamps often sh

Re: Is there a way to get __thismodule__?

2008-03-19 Thread benhoyt
Wow -- thanks, guys. And who said Python only gives you one way to do things. :-) Metaclasses, globals(), and __subclasses__. Thank Duncan for the __subclassess__ tip -- I didn't know about that. I'd totally overlooked globals(). It's exactly what I was looking for -- thanks, Peter. And I like yo

Re: Is there a way to get __thismodule__?

2008-03-18 Thread benhoyt
Replying to myself here, after discovering more. :-) > Is there a way to get __thismodule__ in Python? It looks like __thismodule__ is just sys.modules[__name__]. Neat. Hmmm ... does sys.modules always already contain the currently-being- loaded module? Or is this a hack that only happens to wo

Is there a way to get __thismodule__?

2008-03-18 Thread benhoyt
Is there a way to get __thismodule__ in Python? That is, the current module you're in. Or isn't that known until the end of the module? For instance, if I'm writing a module of message types/classes, like so: class SetupMessage(Message): number = 1 class ResetMessage(Message): number = 2

Re: Double underscores -- ugly?

2008-02-21 Thread benhoyt
> Has anyone thought about alternatives? Is there a previous discussion > on this I can look up? Okay, I just emailed the BDFL and asked if he could tell me the origin of the double underscore syntax for __special__ methods, and what he said I'm pretty sure he won't mind me posting here: > [Guid

Re: Double underscores -- ugly?

2008-02-20 Thread benhoyt
> > Then again, what's stopping us just using a single leading underscore? > > Nobody calls their own private methods _init or _add > > You must be looking at different code from the rest of us. A single > leading underscore on the name *is* the convention for "this attribute > is not part of the

Re: Double underscores -- ugly?

2008-02-19 Thread benhoyt
> My editor actually renders [underscores] as miniature chess pieces. > The bartender said she runs a pre-execution step, that searches and > replaces a double-colon with the underscores. Heh, that makes me think. Great use for character encodings! Just like Tim Hatch's "pybraces", we could use a

Re: Double underscores -- ugly?

2008-02-18 Thread benhoyt
> [Terry Jan Reedy] > No, the reservered special names are supposed to be ugly ;-) -- or at least > to stand out. However, since special methods are almost always called > indirectly by syntax and not directly, only the class writer or reader, but > not users, generally see them. Fair enough, bu

Double underscores -- ugly?

2008-02-18 Thread benhoyt
Hi guys, I've been using Python for some time now, and am very impressed with its lack of red tape and its clean syntax -- both probably due to the BDFL's ability to know when to say "no". Most of the things that "got me" initially have been addressed in recent versions of Python, or are being ad