Best way to capture output from an exec'ed (or such) script?
gagsl-py2 at yahoo.com.ar
Sun Aug 5 11:50:06 CEST 2007
En Sat, 04 Aug 2007 18:52:16 -0300, gregpinero at gmail.com
<gregpinero at gmail.com> escribió:
>> On Aug 2, 7:32 pm, "Gabriel Genellina" <gagsl-... at yahoo.com.ar> wrote:>
>> If your web server is multithreaded (or you use some other way to
>> > many simultaneous requests) you have to be more careful - remember
>> > sys.stdout is global, you must find a way to distinguish between
>> > from different processes all going into the same collector.
> I'm actually worried about this now. Does anyone know of any
> potential solutions? Anything to at least get me started?
You can use threading.currentThread() to distinguish between threads, and
a Lock (or RLock) to ensure the output doesn't get mixed:
t = time.strftime("%x %X", time.localtime())
who = threading.currentThread().getName()
line = "%s (%-15.15s) %s\n" % (t, who, msg)
OutputDebugString("%s (%-15.15s) %s\n" % (t, who, msg))
with logfile() as f:
More information about the Python-list