示例#1
0
文件: scheduler.py 项目: fallen/artiq
 def _do(self):
     while True:
         run = self._get_run()
         if run is None:
             yield from self.pool.state_changed.wait()
         elif isinstance(run, float):
             yield from asyncio_wait_or_cancel([self.pool.state_changed.wait()],
                                               timeout=run)
         else:
             if run.flush:
                 run.status = RunStatus.flushing
                 while not all(r.status in (RunStatus.pending,
                                            RunStatus.deleting)
                               or r is run
                               for r in self.pool.runs.values()):
                     ev = [self.pool.state_changed.wait(),
                           run.worker.closed.wait()]
                     yield from asyncio_wait_or_cancel(
                         ev, return_when=asyncio.FIRST_COMPLETED)
                     if run.worker.closed.is_set():
                         break
                 if run.worker.closed.is_set():
                         continue
             run.status = RunStatus.preparing
             try:
                 yield from run.build()
                 yield from run.prepare()
             except:
                 logger.warning("got worker exception in prepare stage, "
                                "deleting RID %d",
                                run.rid, exc_info=True)
                 self.delete_cb(run.rid)
             else:
                 run.status = RunStatus.prepare_done
示例#2
0
 def _do(self):
     while True:
         run = self._get_run()
         if run is None:
             yield from self.pool.state_changed.wait()
         elif isinstance(run, float):
             yield from asyncio_wait_or_cancel(
                 [self.pool.state_changed.wait()], timeout=run)
         else:
             if run.flush:
                 run.status = RunStatus.flushing
                 while not all(r.status in (RunStatus.pending,
                                            RunStatus.deleting) or r is run
                               for r in self.pool.runs.values()):
                     ev = [
                         self.pool.state_changed.wait(),
                         run.worker.closed.wait()
                     ]
                     yield from asyncio_wait_or_cancel(
                         ev, return_when=asyncio.FIRST_COMPLETED)
                     if run.worker.closed.is_set():
                         break
                 if run.worker.closed.is_set():
                     continue
             run.status = RunStatus.preparing
             try:
                 yield from run.build()
                 yield from run.prepare()
             except:
                 logger.warning(
                     "got worker exception in prepare stage, "
                     "deleting RID %d",
                     run.rid,
                     exc_info=True)
                 self.delete_cb(run.rid)
             else:
                 run.status = RunStatus.prepare_done
示例#3
0
文件: worker.py 项目: fallen/artiq
 def _recv(self, timeout):
     assert self.io_lock.locked()
     fs = yield from asyncio_wait_or_cancel(
         [self.process.stdout.readline(), self.closed.wait()],
         timeout=timeout, return_when=asyncio.FIRST_COMPLETED)
     if all(f.cancelled() for f in fs):
         raise WorkerTimeout("Timeout receiving data from worker")
     if self.closed.is_set():
         raise WorkerError("Data transmission to worker cancelled")
     line = fs[0].result()
     if not line:
         raise WorkerError("Worker ended while attempting to receive data")
     try:
         obj = pyon.decode(line.decode())
     except:
         raise WorkerError("Worker sent invalid PYON data")
     return obj
示例#4
0
文件: worker.py 项目: fallen/artiq
 def _send(self, obj, cancellable=True):
     assert self.io_lock.locked()
     line = pyon.encode(obj)
     self.process.stdin.write(line.encode())
     self.process.stdin.write("\n".encode())
     ifs = [self.process.stdin.drain()]
     if cancellable:
         ifs.append(self.closed.wait())
     fs = yield from asyncio_wait_or_cancel(
         ifs, timeout=self.send_timeout,
         return_when=asyncio.FIRST_COMPLETED)
     if all(f.cancelled() for f in fs):
         raise WorkerTimeout("Timeout sending data to worker")
     for f in fs:
         if not f.cancelled() and f.done():
             f.result()  # raise any exceptions
     if cancellable and self.closed.is_set():
         raise WorkerError("Data transmission to worker cancelled")
示例#5
0
 def _recv(self, timeout):
     assert self.io_lock.locked()
     fs = yield from asyncio_wait_or_cancel(
         [self.process.stdout.readline(),
          self.closed.wait()],
         timeout=timeout,
         return_when=asyncio.FIRST_COMPLETED)
     if all(f.cancelled() for f in fs):
         raise WorkerTimeout("Timeout receiving data from worker")
     if self.closed.is_set():
         raise WorkerError("Data transmission to worker cancelled")
     line = fs[0].result()
     if not line:
         raise WorkerError("Worker ended while attempting to receive data")
     try:
         obj = pyon.decode(line.decode())
     except:
         raise WorkerError("Worker sent invalid PYON data")
     return obj
示例#6
0
 def _send(self, obj, cancellable=True):
     assert self.io_lock.locked()
     line = pyon.encode(obj)
     self.process.stdin.write(line.encode())
     self.process.stdin.write("\n".encode())
     ifs = [self.process.stdin.drain()]
     if cancellable:
         ifs.append(self.closed.wait())
     fs = yield from asyncio_wait_or_cancel(
         ifs,
         timeout=self.send_timeout,
         return_when=asyncio.FIRST_COMPLETED)
     if all(f.cancelled() for f in fs):
         raise WorkerTimeout("Timeout sending data to worker")
     for f in fs:
         if not f.cancelled() and f.done():
             f.result()  # raise any exceptions
     if cancellable and self.closed.is_set():
         raise WorkerError("Data transmission to worker cancelled")