3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-01 01:09:22 +01:00

core: Properly track whether we should actually remove the PID file

Previously, PyLink spuriously removed PID files even if -n/--no-check-pid was set or if PID file checking caused PyLink to quit
This commit is contained in:
James Lu 2017-07-20 21:13:01 +08:00
parent 2113f834a3
commit 91659ea992
3 changed files with 13 additions and 6 deletions

View File

@ -24,13 +24,16 @@ def _print_remaining_threads():
log.debug('shutdown(): Remaining threads: %s', ['%s/%s' % (t.name, t.ident) for t in threading.enumerate()])
def _remove_pid():
# Remove our pid file.
pidfile = "%s.pid" % conf.confname
log.info("Removing PID file %r.", pidfile)
try:
os.remove(pidfile)
except OSError:
log.exception("Failed to remove PID file %r, ignoring..." % pidfile)
if world._should_remove_pid:
# Remove our pid file.
log.info("Removing PID file %r.", pidfile)
try:
os.remove(pidfile)
except OSError:
log.exception("Failed to remove PID file %r, ignoring..." % pidfile)
else:
log.debug('Not removing PID file %s as world._should_remove_pid is False.' % pidfile)
def _kill_plugins(irc=None):
log.info("Shutting down plugins.")

View File

@ -50,6 +50,7 @@ def main():
if not args.no_pid:
with open('%s.pid' % conf.confname, 'w') as f:
f.write(str(os.getpid()))
world._should_remove_pid = True
# Import plugins first globally, because they can listen for events
# that happen before the connection phase.

View File

@ -33,3 +33,6 @@ fallback_hostname = 'pylink.int'
# Defines messages to be logged as soon as the log system is set up, for modules like conf that are
# initialized before log. This is processed (and then not used again) when the log module loads.
log_queue = deque()
# Determines whether we have a PID file that needs to be removed.
_should_remove_pid = False