From 5917da0e23dcaadd633a97be2d3495941f31fe0f Mon Sep 17 00:00:00 2001 From: brown27h <61562392+brown27h@users.noreply.github.com> Date: Thu, 8 Apr 2021 23:07:02 -0700 Subject: [PATCH] Update ttt.py to run on windows To run this example game on a windows machine, first install the curses library with 'pip install windows-curses'. Then run the program with 'python' or 'py', it will not run with 'python3'. ttt.py has been updated to handle unexpected exceptions thrown by windows when attempting to receive from a non-blocking socket that has not received anything. --- examples/ttt.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/ttt.py b/examples/ttt.py index 937fa17..35369fa 100755 --- a/examples/ttt.py +++ b/examples/ttt.py @@ -6,7 +6,7 @@ from socket import (socket, AF_INET, SOCK_STREAM, IPPROTO_TCP) from socket import timeout as socket_timeout from socket import error as socket_error -from errno import EAGAIN +import errno import json @@ -286,7 +286,7 @@ def do_communication (self): except socket_timeout: pass except socket_error as e: - if e.errno != EAGAIN: raise + if e.errno != errno.EAGAIN: raise except Exception: add_hist("Socket send error") self.close() @@ -304,8 +304,10 @@ def do_communication (self): msg,self.inbuf = self.inbuf.split(b"\n", 1) msg = json.loads(msg) msgs.append(msg) + except WindowsError as e: + if e.winerror != errno.WSAEWOULDBLOCK: raise except socket_error as e: - if e.errno != EAGAIN: raise + if e.errno != errno.EAGAIN: raise except socket_timeout: pass except Exception as e: