Skip to content

Commit

Permalink
Fixed signal handling. Not all unused parameters can be removed, espe…
Browse files Browse the repository at this point in the history
…cially in callbacks, read docs before "fixing" code
  • Loading branch information
linuxdaemon committed Nov 16, 2016
1 parent db7efe8 commit f87f14f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 7 additions & 2 deletions cloudbot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,18 @@ def main():
original_sigint = signal.getsignal(signal.SIGINT)

# define closure for signal handling
def exit_gracefully():
# The handler is called with two arguments: the signal number and the current stack frame
# These parameters should NOT be removed
def exit_gracefully(signum, frame):
nonlocal stopped_while_restarting
if not _bot:
# we are currently in the process of restarting
stopped_while_restarting = True
else:
_bot.loop.call_soon_threadsafe(lambda: asyncio.async(_bot.stop("Killed"), loop=_bot.loop))
_bot.loop.call_soon_threadsafe(
lambda: asyncio.async(_bot.stop("Killed (Received SIGINT {})".format(signum)), loop=_bot.loop))

logger.warn("Bot received Signal Interrupt ({})".format(signum))

# restore the original handler so if they do it again it triggers
signal.signal(signal.SIGINT, original_sigint)
Expand Down
4 changes: 3 additions & 1 deletion plugins/profiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ def pympler_diff():

# # Provide an easy way to get a threaddump, by using SIGUSR1 (only on POSIX systems)
if os.name == "posix":
def debug():
# The handler is called with two arguments: the signal number and the current stack frame
# These parameters should NOT be removed
def debug(sig, frame):
print(get_thread_dump())

signal.signal(signal.SIGUSR1, debug) # Register handler

0 comments on commit f87f14f

Please sign in to comment.