3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-12-24 11:42:51 +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

(cherry picked from commit 91659ea992)
This commit is contained in:
James Lu 2017-07-20 21:33:17 +08:00
parent b90da19dfa
commit dac0d5b234
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.")

1
pylink
View File

@ -58,6 +58,7 @@ if __name__ == '__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