More tweaks to networking code, starting network game seems to stop all gui events.

This commit is contained in:
Anna Rose Wiggins 2012-04-15 23:43:46 -04:00
parent c7947d9790
commit 7abef7b37d
3 changed files with 55 additions and 32 deletions

View file

@ -7,33 +7,34 @@
# if it exists.
import threading
import gtpsocket
class NetworkThread(threading.Thread):
dispatcher = {
'quit': do_quit,
'boardsize': do_boardsize,
'clear_board': do_clear_board,
'komi': do_komi,
'play': do_play,
'genmove': do_genmove
}
def __init__(self, goban, socket):
threading.Thread.__init__(self)
self.dispatcher = {
'quit': self.do_quit,
'boardsize': self.do_boardsize,
'clear_board': self.do_clear_board,
'komi': self.do_komi,
'play': self.do_play,
'genmove': self.do_genmove
}
self.goban = goban
self.goban_lock = threading.Lock()
self.socket = GTPSocket(socket)
self.socket = gtpsocket.GTPSocket(socket)
self.send_lock = threading.Lock()
GTPSocket.known_cmds = GTPSocket.known_cmds & set(NetworkThread.dispatcher.keys())
gtpsocket.GTPSocket.known_cmds = gtpsocket.GTPSocket.known_cmds & set(self.dispatcher.keys())
def run(self):
while True:
gtp = self.socket.get()
if gtp is not None:
NetworkThread.dispatcher[gtp.command](gtp)
self.dispatcher[gtp.command](gtp)
def do_quit(self, gtp):