Skip to content

Commit

Permalink
Log when terminated
Browse files Browse the repository at this point in the history
The twarc command catches SIGTERM so that users can ctrl-c to stop the
process. But it did so quietly, which could be perplexing when users put
twarc into the background and then logged out (which can cause SIGTERM
being sent to the process). To aid in diagnosing when/why things stop
this commit adds logging to when twarc is shutting down. fixes #319
  • Loading branch information
edsu committed Apr 12, 2020
1 parent b7e23ce commit 0e6bdfd
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from setuptools import setup

# Also in twarc/__init__.py
__version__ = '1.8.1'
__version__ = '1.8.2'

with open("README.md") as f:
long_description = f.read()
Expand Down
2 changes: 1 addition & 1 deletion twarc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '1.8.1' # also in setup.py
__version__ = '1.8.2' # also in setup.py

from .client import Twarc
from .command import main
7 changes: 5 additions & 2 deletions twarc/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,11 @@ def main():
format="%(asctime)s %(levelname)s %(message)s"
)

# catch ctrl-c so users don't see a stack trace
signal.signal(signal.SIGINT, lambda signal, frame: sys.exit(0))
# log and stop when process receives SIGINT
def stop(signal, frame):
log.warn('process received SIGNT, stopping')
sys.exit(0)
signal.signal(signal.SIGINT, stop)

if command == "version":
print("twarc v%s" % __version__)
Expand Down

0 comments on commit 0e6bdfd

Please sign in to comment.