[Zope-dev] Re: zdaemon fix
Guido van Rossum
guido@python.org
Sat, 05 Oct 2002 04:29:55 -0400
BTW, here's the patch I propose:
*** Daemon.py 14 Aug 2002 22:12:52 -0000 1.11
--- Daemon.py 5 Oct 2002 08:14:51 -0000
***************
*** 17,22 ****
--- 17,28 ----
import zLOG
from SignalPasser import SignalPasser
+ # If zdaemon finds that it is continuously respawning more than 10
+ # times in 2 minutes, it will assume that there is an error, log a
+ # PANIC level message, and exit.
+ RESPAWN_TIME = 120 # 2 minutes
+ RESPAWN_LIMIT = 10 # 10 times
+
pyth = sys.executable
class DieNow(Exception):
***************
*** 32,38 ****
--- 38,54 ----
if not os.environ.has_key('Z_DEBUG_MODE'):
detach() # detach from the controlling terminal
+ starttimes = [] # for RESPAWN_LIMIT
while 1:
+ # Give up if respawning too often
+ starttimes.append(time.time())
+ if len(starttimes) > RESPAWN_LIMIT:
+ del starttimes[0]
+ if starttimes[-1] - starttimes[0] < RESPAWN_TIME:
+ pstamp('Respawning more than %d times in %d seconds. Quit.' %
+ (RESPAWN_LIMIT, RESPAWN_TIME), zLOG.PANIC)
+ sys.exit(1)
+ del starttimes[0]
try:
pid = os.fork()
if pid:
While we're improving zdaemon, I have two other suggestions:
- Use grown-up language in log messages rather than "Aiieee!" and
"Houston, we have forked"
- Why does zdaemon add "zdaemon: <timestamp>: " to its log messages?
That info is already added by zLOG.
A typical set of zdaemon log messages now looks like this:
------
2002-10-05T04:23:31 INFO(0) zdaemon zdaemon: Sat Oct 5 04:23:31 2002: Houston,
we have forked: pid 2915
------
2002-10-05T04:24:12 ERROR(200) zdaemon zdaemon: Sat Oct 5 04:24:12 2002:
Aiieee! Process 2915 terminated normally, exit status: 1
------
while it could look like this:
------
2002-10-05T04:23:31 INFO(0) zdaemon Started subprocess: pid 2915
------
2002-10-05T04:24:12 ERROR(200) zdaemon Process 2915 terminated normally, exit
status: 1
------
--Guido van Rossum (home page: http://www.python.org/~guido/)