diff --git a/client.py b/client.py index 4bfcd66..c3de9f9 100755 --- a/client.py +++ b/client.py @@ -49,4 +49,7 @@ def RunClient(): if __name__ == '__main__': # if this script is called from the command line, and thus not imported # start a client and start sending messages - RunClient() + try: + RunClient() + except KeyboardInterrupt: + print 'Closing client' diff --git a/vloed.py b/vloed.py index 602947c..8798f4e 100755 --- a/vloed.py +++ b/vloed.py @@ -8,17 +8,20 @@ code from https://github.com/defnull/pixelflut/ __version__ = 0.3 __author__ = "Jan Klopper " +# import gevent monkeypatching and perform patch_all before anything else to +# avoid nasty eception on python closing time +from gevent import spawn, monkey +monkey.patch_all() + import pygame from pygame import locals as pygamelocals import struct import time import socket -from gevent import spawn, monkey from gevent.server import DatagramServer from gevent.queue import Queue -monkey.patch_all() UDP_IP = "127.0.0.1" UDP_PORT = 5005 DISCOVER_PORT = 5006 @@ -335,4 +338,7 @@ if __name__ == '__main__': parser.add_option('-f', action="store", dest="factor", default=1, type="int") options, remainder = parser.parse_args() - RunServer(options) + try: + RunServer(options) + except KeyboardInterrupt: + print 'Closing server'