Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't close the logfile -- just flush it -- on reactor shutdown #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions foolscap/logging/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,9 @@ def __init__(self, filename, level=OPERATIONAL):
}}
pickle.dump(header, self._logFile)

def stop_on_shutdown(self):
def flush_on_shutdown(self):
from twisted.internet import reactor
reactor.addSystemEventTrigger("after", "shutdown", self._stop)
reactor.addSystemEventTrigger("after", "shutdown", self._flush)

def msg(self, event):
threshold = self._level
Expand All @@ -439,9 +439,8 @@ def msg(self, event):
}
pickle.dump(e, self._logFile, 2)

def _stop(self):
self._logFile.close()
del self._logFile
def _flush(self):
self._logFile.flush()


# remove the key, so any child processes won't try to log to (and thus
Expand All @@ -454,7 +453,7 @@ def _stop(self):
try:
_floglevel = int(os.environ.get("FLOGLEVEL", str(OPERATIONAL)))
lfo = LogFileObserver(_flogfile, _floglevel)
lfo.stop_on_shutdown()
lfo.flush_on_shutdown()
theLogger.addObserver(lfo.msg)
#theLogger.set_generation_threshold(UNUSUAL, "foolscap.negotiation")
except IOError:
Expand Down
4 changes: 2 additions & 2 deletions foolscap/test/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -1757,7 +1757,7 @@ def create_logfile(self):
l.msg("four")
d = fireEventually()
def _done(res):
lfo._stop()
lfo._flush()
#events = self._read_logfile(fn)
#self.failUnlessEqual(len(events), 1+3)
return fn
Expand Down Expand Up @@ -2055,7 +2055,7 @@ def test_basic(self):
d = fireEventually()
def _created(res):
l.removeObserver(ob.msg)
ob._stop()
ob._flush()
argv = ["-p", "tcp:0:interface=127.0.0.1",
"--quiet",
fn]
Expand Down