python - Is chronological order of logging messages guaranteed? -
i'm using logging
module log messages application server. more specifically, use streamhandler log messages stdout/stderr, , use supervisord
log messages files (since server process monitored supervisord
).
my main question is, order of messages in log file always truthfully reflect order of execution of code? example, if message a: log msg a
appears before message b: log msg b
in log file, can 100% line of code logs message a
executed before line of code logs message b
, if timestamps of 2 messages in log file same?
you can't be 100% sure, i'm pretty sure.
although logging module locks output file before writing it, if you're running multiple threads or processes there's no guarantee code called logging.warning("a")
or whatever acquires lock if several other threads trying same @ around same time.
see docs logging , its source. see uses threading.rlock
, the docs say:
if more 1 thread blocked waiting until lock unlocked, 1 @ time able grab ownership of lock. there no return value in case.
we can't entirely of thread gets lock first, problem.
Comments
Post a Comment