From 125503139e62ba7f1b33925ee04dacc9797cea45 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Sat, 3 Oct 2015 14:33:18 +0800 Subject: [PATCH] remove workaround for Python bug in asyncio process.wait(). Requires Python 3.5. Closes #58 --- artiq/frontend/artiq_ctlmgr.py | 10 +++++----- artiq/master/worker.py | 10 ++++------ artiq/tools.py | 23 ----------------------- conda/artiq/meta.yaml | 4 ++-- doc/manual/installing.rst | 8 ++++---- setup.py | 4 ++-- 6 files changed, 17 insertions(+), 42 deletions(-) diff --git a/artiq/frontend/artiq_ctlmgr.py b/artiq/frontend/artiq_ctlmgr.py index 878d6e649..273cae9af 100755 --- a/artiq/frontend/artiq_ctlmgr.py +++ b/artiq/frontend/artiq_ctlmgr.py @@ -11,7 +11,7 @@ import socket from artiq.protocols.sync_struct import Subscriber from artiq.protocols.pc_rpc import AsyncioClient, Server from artiq.tools import verbosity_args, init_logger -from artiq.tools import TaskObject, asyncio_process_wait_timeout, Condition +from artiq.tools import TaskObject, Condition logger = logging.getLogger(__name__) @@ -88,8 +88,8 @@ class Controller: def _wait_and_ping(self): while True: try: - yield from asyncio_process_wait_timeout(self.process, - self.ping_timer) + yield from asyncio.wait_for(self.process.wait(), + self.ping_timer) except asyncio.TimeoutError: logger.debug("pinging controller %s", self.name) ok = yield from self._ping() @@ -137,8 +137,8 @@ class Controller: "command, killing", self.name) self.process.kill() try: - yield from asyncio_process_wait_timeout(self.process, - self.term_timeout) + yield from asyncio.wait_for(self.process.wait(), + self.term_timeout) except: logger.warning("Controller %s failed to exit, killing", self.name) diff --git a/artiq/master/worker.py b/artiq/master/worker.py index 100b4e4ee..1bb36f94d 100644 --- a/artiq/master/worker.py +++ b/artiq/master/worker.py @@ -7,8 +7,7 @@ import time from functools import partial from artiq.protocols import pyon -from artiq.tools import (asyncio_process_wait_timeout, asyncio_process_wait, - asyncio_wait_or_cancel) +from artiq.tools import asyncio_wait_or_cancel logger = logging.getLogger(__name__) @@ -97,15 +96,14 @@ class Worker: logger.warning("failed to send terminate command to worker" " (RID %s), killing", self.rid, exc_info=True) self.process.kill() - yield from asyncio_process_wait(self.process) + yield from self.process.wait() return try: - yield from asyncio_process_wait_timeout(self.process, - term_timeout) + yield from asyncio.wait_for(self.process.wait(), term_timeout) except asyncio.TimeoutError: logger.warning("worker did not exit (RID %s), killing", self.rid) self.process.kill() - yield from asyncio_process_wait(self.process) + yield from self.process.wait() else: logger.debug("worker exited gracefully (RID %s)", self.rid) finally: diff --git a/artiq/tools.py b/artiq/tools.py index 499341d04..321c87bfe 100644 --- a/artiq/tools.py +++ b/artiq/tools.py @@ -88,29 +88,6 @@ def exc_to_warning(coro): exc_info=True) -@asyncio.coroutine -def asyncio_process_wait_timeout(process, timeout): - # In Python < 3.5, asyncio.wait_for(process.wait(), ... - # causes a futures.InvalidStateError inside asyncio if and when the - # process terminates after the timeout. - # Work around this problem. - @asyncio.coroutine - def process_wait_returncode_timeout(): - while True: - if process.returncode is not None: - break - yield from asyncio.sleep(0.1) - yield from asyncio.wait_for(process_wait_returncode_timeout(), - timeout=timeout) - -@asyncio.coroutine -def asyncio_process_wait(process): - r = True - while r: - f, p = yield from asyncio.wait([process.stdout.read(1024)]) - r = f.pop().result() - - @asyncio.coroutine def asyncio_wait_or_cancel(fs, **kwargs): fs = [asyncio.async(f) for f in fs] diff --git a/conda/artiq/meta.yaml b/conda/artiq/meta.yaml index c24da2c4b..6dacc0293 100644 --- a/conda/artiq/meta.yaml +++ b/conda/artiq/meta.yaml @@ -28,14 +28,14 @@ build: requirements: build: - - python >=3.4.4 + - python >=3.5.0 - setuptools - numpy - migen - pyelftools - binutils-or1k-linux run: - - python >=3.4.4 + - python >=3.5.0 - llvmlite-artiq - scipy - numpy diff --git a/doc/manual/installing.rst b/doc/manual/installing.rst index 312e68a6b..8cb1727a2 100644 --- a/doc/manual/installing.rst +++ b/doc/manual/installing.rst @@ -13,9 +13,9 @@ Installing using conda Installing Anaconda or Miniconda ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -* You can either install Anaconda (chose Python 3.4) from https://store.continuum.io/cshop/anaconda/ +* You can either install Anaconda (chose Python 3.5) from https://store.continuum.io/cshop/anaconda/ -* Or install the more minimalistic Miniconda (chose Python 3.4) from http://conda.pydata.org/miniconda.html +* Or install the more minimalistic Miniconda (chose Python 3.5) from http://conda.pydata.org/miniconda.html .. warning:: If you are installing on Windows, chose the Windows 32-bit version regardless of whether you have @@ -148,7 +148,7 @@ These steps are required to generate bitstream (``.bit``) files, build the MiSoC $ python3 setup.py develop --user .. note:: - The options ``develop`` and ``--user`` are for setup.py to install Migen in ``~/.local/lib/python3.4``. + The options ``develop`` and ``--user`` are for setup.py to install Migen in ``~/.local/lib/python3.5``. .. _install-xc3sprog: @@ -369,7 +369,7 @@ This command installs all the required packages: :: $ sudo apt-get install build-essential autotools-dev file git patch perl xutils-dev python3-pip texinfo flex bison libmpc-dev python3-serial python3-dateutil python3-prettytable python3-setuptools python3-numpy python3-scipy python3-sphinx python3-h5py python3-dev python-dev subversion cmake libusb-dev libftdi-dev pkg-config libffi-dev libgit2-dev -Note that ARTIQ requires Python 3.4.4 or above. +Note that ARTIQ requires Python 3.5.0 or above. To set user permissions on the JTAG and serial ports of the Pipistrello, create a ``/etc/udev/rules.d/30-usb-papilio.rules`` file containing the following: :: diff --git a/setup.py b/setup.py index 34e112884..9ca327bde 100755 --- a/setup.py +++ b/setup.py @@ -5,8 +5,8 @@ import sys import os -if sys.version_info[:3] < (3, 4, 4): - raise Exception("You need Python 3.4.4+") +if sys.version_info[:3] < (3, 5, 0): + raise Exception("You need Python 3.5.0+") class PushDocCommand(Command):