简体   繁体   中英

Keeping python daemon alive

We develop some small services to run like unix daemons.

Our first implementation was dependent of twisted reactor. The reactor instance was our artifact to keep OS process alive and running without stop after subprocess call.

Recently, we removed Twisted dependencies for these modules, remaining the necessity to keep processes running after subprocess call. We put a ' while True: time.sleep(.1) ' statement in the end of our "main()" method and it works fine.

With the time.sleep(.1) call, our performance is wasting performance, considering wake up events ~600 times per minute. It's not a good for our application performance. If we replace

while True:
    time.sleep(.1)

by

while True:
    pass

it consumes so much CPU time (~1.7% of a i5, continually).

There are better or balanced alternative solutions with less CPU time occupation and with responsive performance for the following options?

reactor.run()

and

while True:
    time.sleep(.1)

I found some similar answers and discussions on stackoverflow and web, but did'n find a clear discussion about it considering python.

Perhaps the solution is to simply use a module that is...was* going to go into the standard library for this.

https://pypi.python.org/pypi/python-daemon/

apparently 3143 has been deferred, but the pypi link is to the implementation of the pep.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM