Skip to content
This repository has been archived by the owner on Feb 13, 2020. It is now read-only.

Commit

Permalink
- Collector #1939: When running as a service, Zope could
Browse files Browse the repository at this point in the history
        potentially collect too much log output filling the NT Event
        Log. When that happened, a 'print' during exception handling
        would cause an IOError in the restart code causing the service
        not to restart automatically.

        Problem is that a service/pythonw.exe process *always* has an
        invalid sys.stdout.  But due to the magic of buffering, small
        print statements would not fail - but once the file actually
        got written to, the error happened.  Never a problem when
        debugging, as the process has a console, and hence a valid
        stdout.
  • Loading branch information
sidnei committed Dec 21, 2005
1 parent 3f7e3ce commit 744b65f
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions service.py
Expand Up @@ -36,8 +36,10 @@
# (except obviously via the event log entry)
# Size of the blocks we read from the child process's output.
CHILDCAPTURE_BLOCK_SIZE = 80
# The number of BLOCKSIZE blocks we keep as process output.
CHILDCAPTURE_MAX_BLOCKS = 200
# The number of BLOCKSIZE blocks we keep as process output. This gives
# is 4k, which should be enough to see any tracebacks etc, but not so
# large as to prematurely fill the event log.
CHILDCAPTURE_MAX_BLOCKS = 50

class Service(win32serviceutil.ServiceFramework):
"""Base class for a Windows Server to manage an external process.
Expand Down Expand Up @@ -108,7 +110,10 @@ def logmsg(self, event):
except win32api.error, details:
# Failed to write a log entry - most likely problem is
# that the event log is full. We don't want this to kill us
print "FAILED to write INFO event", event, ":", details
try:
print "FAILED to write INFO event", event, ":", details
except IOError:
pass

def _dolog(self, func, msg):
try:
Expand All @@ -118,8 +123,13 @@ def _dolog(self, func, msg):
except win32api.error, details:
# Failed to write a log entry - most likely problem is
# that the event log is full. We don't want this to kill us
print "FAILED to write event log entry:", details
print msg
try:
print "FAILED to write event log entry:", details
print msg
except IOError:
# And if running as a service, its likely our sys.stdout
# is invalid
pass

def info(self, s):
self._dolog(servicemanager.LogInfoMsg, s)
Expand Down

0 comments on commit 744b65f

Please sign in to comment.