
Move the code into the main() routine and pass main_loop as a parameter to the signal handler.
52 lines
1.5 KiB
Python
Executable File
52 lines
1.5 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# -*- Mode: python; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
#
|
|
# This program is free software; you can redistribute it and/or modify it under
|
|
# the terms of the GNU Lesser General Public License as published by the Free
|
|
# Software Foundation; either version 2 of the License, or (at your option) any
|
|
# later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
|
# details.
|
|
#
|
|
# You should have received a copy of the GNU Lesser General Public License along
|
|
# with this program; if not, write to the Free Software Foundation, Inc., 51
|
|
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
#
|
|
# Copyright (C) 2014 Aleksander Morgado <aleksander@aleksander.es>
|
|
#
|
|
|
|
import signal
|
|
|
|
from gi.repository import GLib
|
|
|
|
import ModemWatcher
|
|
|
|
|
|
def signal_handler(loop):
|
|
"""SIGHUP and SIGINT handler."""
|
|
loop.quit()
|
|
|
|
|
|
def main():
|
|
"""Main routine."""
|
|
# Create modem watcher
|
|
ModemWatcher.ModemWatcher()
|
|
|
|
# Main loop
|
|
main_loop = GLib.MainLoop()
|
|
GLib.unix_signal_add(
|
|
GLib.PRIORITY_HIGH, signal.SIGHUP, signal_handler, main_loop)
|
|
GLib.unix_signal_add(
|
|
GLib.PRIORITY_HIGH, signal.SIGTERM, signal_handler, main_loop)
|
|
try:
|
|
main_loop.run()
|
|
except KeyboardInterrupt:
|
|
pass
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|