Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/artiq
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: da70f8b88cbf
Choose a base ref
...
head repository: m-labs/artiq
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 1bc406162029
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on Oct 19, 2015

  1. Copy the full SHA
    71d2e3a View commit details
  2. Copy the full SHA
    1bc4061 View commit details
Showing with 11 additions and 10 deletions.
  1. +2 −9 artiq/protocols/logging.py
  2. +3 −1 artiq/protocols/sync_struct.py
  3. +6 −0 artiq/tools.py
11 changes: 2 additions & 9 deletions artiq/protocols/logging.py
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
import logging

from artiq.protocols.asyncio_server import AsyncioServer
from artiq.tools import TaskObject
from artiq.tools import TaskObject, workaround_asyncio263


logger = logging.getLogger(__name__)
@@ -119,19 +119,12 @@ async def _do(self):
try:
reader, writer = await asyncio.open_connection(self.host,
self.port)
detect_close = asyncio.ensure_future(reader.read(1))
writer.write(_init_string)
while True:
message = await self._queue.get() + "\n"
writer.write(message.encode())
await workaround_asyncio263()
await writer.drain()
# HACK: detect connection termination through the completion
# of a read operation. For some reason, write/drain operations
# on a closed socket do not raise exceptions, but print
# "asyncio:socket.send() raised exception."
if detect_close.done():
await asyncio.sleep(self.reconnect_timer)
break
except asyncio.CancelledError:
return
except:
4 changes: 3 additions & 1 deletion artiq/protocols/sync_struct.py
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@

from artiq.protocols import pyon
from artiq.protocols.asyncio_server import AsyncioServer
from artiq.tools import workaround_asyncio263


_init_string = b"ARTIQ sync_struct\n"
@@ -233,10 +234,11 @@ async def _handle_connection_cr(self, reader, writer):
line = await queue.get()
writer.write(line)
# raise exception on connection error
await workaround_asyncio263()
await writer.drain()
finally:
self._recipients[notifier_name].remove(queue)
except ConnectionResetError:
except (ConnectionResetError, BrokenPipeError):
# subscribers disconnecting are a normal occurence
pass
finally:
6 changes: 6 additions & 0 deletions artiq/tools.py
Original file line number Diff line number Diff line change
@@ -175,3 +175,9 @@ def notify(self):
for fut in self._waiters:
if not fut.done():
fut.set_result(False)


# See: https://github.com/python/asyncio/issues/263
@asyncio.coroutine
def workaround_asyncio263():
yield