From 04b7d9eedace7c61fec9f306b8c0a1037b2d5de0 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Tue, 14 May 2013 19:59:19 +0200 Subject: [PATCH] Fix compatibility with Python 3.3.1. --- README.md | 3 +-- src/world.py | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 329af616e..c1683171d 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,7 @@ Master branch: [![Build Status (master branch)](https://travis-ci.org/ProgVal/Li Testing branch: [![Build Status (testing branch)](https://travis-ci.org/ProgVal/Limnoria.png?branch=testing)](https://travis-ci.org/ProgVal/Limnoria) -Limnoria is tested with Python 2.6, 2.7, 3.2, and Pypy. Python 2.5 is not supported. -Python 3.3 is not fully supported because of a [bug in Python](http://bugs.python.org/issue17856) +Limnoria is tested with Python 2.6, 2.7, 3.2, 3.3, and Pypy. Python 2.5 and older versions are not supported. # EVERYONE: diff --git a/src/world.py b/src/world.py index 584eee9ca..980e95783 100644 --- a/src/world.py +++ b/src/world.py @@ -36,8 +36,9 @@ import os import sys import time import atexit +import select import threading -import multiprocessing # python 2.6 and later! +import multiprocessing import re @@ -73,6 +74,28 @@ class SupyProcess(multiprocessing.Process): super(SupyProcess, self).__init__(*args, **kwargs) log.debug('Spawning process %q.', self.name) +if sys.version_info[0:3] == (3, 3, 1) and hasattr(select, 'poll'): + # http://bugs.python.org/issue17707 + import multiprocessing.connection + def _poll(fds, timeout): + if timeout is not None: + timeout = int(timeout * 1000) # timeout is in milliseconds + fd_map = {} + pollster = select.poll() + for fd in fds: + pollster.register(fd, select.POLLIN) + if hasattr(fd, 'fileno'): + fd_map[fd.fileno()] = fd + else: + fd_map[fd] = fd + ls = [] + for fd, event in pollster.poll(timeout): + if event & select.POLLNVAL: + raise ValueError('invalid file descriptor %i' % fd) + ls.append(fd_map[fd]) + return ls + multiprocessing.connection._poll = _poll + commandsProcessed = 0