add exit messages and make sure we dont trigger some weird threading keyError that happens on python clean up by calling monkey patching as first import

This commit is contained in:
Jan Klopper 2016-06-22 12:44:44 +02:00
parent 9b6190b186
commit 9cfae29dc7
2 changed files with 13 additions and 4 deletions

View file

@ -49,4 +49,7 @@ def RunClient():
if __name__ == '__main__': if __name__ == '__main__':
# if this script is called from the command line, and thus not imported # if this script is called from the command line, and thus not imported
# start a client and start sending messages # start a client and start sending messages
RunClient() try:
RunClient()
except KeyboardInterrupt:
print 'Closing client'

View file

@ -8,17 +8,20 @@ code from https://github.com/defnull/pixelflut/
__version__ = 0.3 __version__ = 0.3
__author__ = "Jan Klopper <jan@underdark.nl>" __author__ = "Jan Klopper <jan@underdark.nl>"
# 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 import pygame
from pygame import locals as pygamelocals from pygame import locals as pygamelocals
import struct import struct
import time import time
import socket import socket
from gevent import spawn, monkey
from gevent.server import DatagramServer from gevent.server import DatagramServer
from gevent.queue import Queue from gevent.queue import Queue
monkey.patch_all()
UDP_IP = "127.0.0.1" UDP_IP = "127.0.0.1"
UDP_PORT = 5005 UDP_PORT = 5005
DISCOVER_PORT = 5006 DISCOVER_PORT = 5006
@ -335,4 +338,7 @@ if __name__ == '__main__':
parser.add_option('-f', action="store", dest="factor", default=1, parser.add_option('-f', action="store", dest="factor", default=1,
type="int") type="int")
options, remainder = parser.parse_args() options, remainder = parser.parse_args()
RunServer(options) try:
RunServer(options)
except KeyboardInterrupt:
print 'Closing server'