Registration in several shared routines / lakes / microflows with Gevent?

What is the best approach for logging events that span multiple running collaborative routines / microflows / Greenlets using Python gevent?

Examples of events that I would like to log might include creating new connections or removing connections to the socket server.

Along this line of thought - is it possible that the "generated" cooperative routines are registered in a single file? Is it even advisable because of potential simultaneous attempts to write to this file?

+4
source share
1 answer

If this is just one process, then no, they cannot write at the same time. Greens all work in the same OS thread and are planned together, only one can work at a time.

with open('log', 'w') as log: jobs = [gevent.spawn(log.write, 'event %d' % i) for i in range(10)] gevent.joinall(jobs) 

... will cause the potions to be logged one by one.

If you have multiple processes, I suggest logging in to redis or perhaps using zeromq to log into a dedicated daemon. Or use some other external logging daemon.

+3
source

All Articles