Skip to content

Commit

Permalink
[*] use a pipe to stop waiting for stdin on shutdown.
Browse files Browse the repository at this point in the history
  • Loading branch information
StyXman committed Dec 2, 2015
1 parent 3fe7d03 commit 9b38c24
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions ayrton/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import ctypes
import os
import traceback
from select import select

import logging
logger= logging.getLogger ('ayrton.remote')
Expand All @@ -44,6 +45,8 @@ def __init__ (self, src, dst):
logger.debug ('CopyThread %s (%s -> %s)', self, src, dst)
self.src= self.dup (src)
self.dst= self.dup (dst)
if isinstance (src, int):
self.finished= os.pipe ()

def dup (self, o):
try:
Expand Down Expand Up @@ -77,6 +80,15 @@ def run (self):
# so, copy by hand
while True:
try:
if isinstance (self.src, int):
# this is stdin
# we must finish without reading from it
# if a signal comes via self.finished
ready= select ([self.src, self.finished[0]], [], [])
if self.finished[0] in ready:
self.close_file (self.finished[0])
break

data= self.read ()
logger.debug ('%s -> %s: %s', self.src, self.dst, data)
# ValueError: read of closed file
Expand All @@ -97,6 +109,9 @@ def run (self):
def close (self):
self.close_file (self.src)
self.close_file (self.dst)
if isinstance (self.src, int):
# send the finished signal
self.close_file (self.finished[1])

def close_file (self, f):
logger.debug ('closing %s', f)
Expand Down

0 comments on commit 9b38c24

Please sign in to comment.