python - Mechanisms for creating long-running process -
are there alternative mechanism(s) creating long-running process besides running infinite loop?
the common pattern seems this:
while true: # check condition or waiting event # processing time.sleep(0.01)
i particularly interested in scenario process acts worker listens event (e.g. waiting on task queue).
what performance characteristics of alternative approaches?
prior art on "wait , process job" thing has been done few different ways:
- worker processes or threads (see
multiprocessing
,threading
helpful primitives) - event-based processing (asyncio, twisted, , few others). asyncronous io library raises event when data on stdin or whatever pipe choose.
- single-threaded io buffer. depending on desired load characteristics, reasonable worker processes wait on io , process when comes. no fancy queueing. let kernel buffer io , calling process block when gets full.
Comments
Post a Comment