Exemplo n.º 1
0
 async def start_process(self, args, stdin):
     if self.starting_stopping:
         return
     self.starting_stopping = True
     try:
         self.ipc = AppletIPCServer(self.datasets_sub)
         env = os.environ.copy()
         env["PYTHONUNBUFFERED"] = "1"
         env["ARTIQ_APPLET_EMBED"] = self.ipc.get_address()
         try:
             await self.ipc.create_subprocess(
                 *args,
                 stdin=None if stdin is None else subprocess.PIPE,
                 stdout=subprocess.PIPE,
                 stderr=subprocess.PIPE,
                 env=env,
                 start_new_session=True)
         except:
             logger.warning("Applet %s failed to start",
                            self.applet_name,
                            exc_info=True)
             return
         if stdin is not None:
             self.ipc.process.stdin.write(stdin.encode())
             self.ipc.process.stdin.write_eof()
         asyncio.ensure_future(
             LogParser(self._get_log_source).stream_task(
                 self.ipc.process.stdout))
         asyncio.ensure_future(
             LogParser(self._get_log_source).stream_task(
                 self.ipc.process.stderr))
         self.ipc.start_server(self.embed, self.fix_initial_size)
     finally:
         self.starting_stopping = False
Exemplo n.º 2
0
 async def _create_process(self, log_level):
     if self.ipc is not None:
         return  # process already exists, recycle
     await self.io_lock.acquire()
     try:
         if self.closed.is_set():
             raise WorkerError("Attempting to create process after close")
         self.ipc = pipe_ipc.AsyncioParentComm()
         env = os.environ.copy()
         env["PYTHONUNBUFFERED"] = "1"
         await self.ipc.create_subprocess(sys.executable,
                                          "-m",
                                          "artiq.master.worker_impl",
                                          self.ipc.get_address(),
                                          str(log_level),
                                          stdout=subprocess.PIPE,
                                          stderr=subprocess.PIPE,
                                          env=env,
                                          start_new_session=True)
         asyncio.ensure_future(
             LogParser(self._get_log_source).stream_task(
                 self.ipc.process.stdout))
         asyncio.ensure_future(
             LogParser(self._get_log_source).stream_task(
                 self.ipc.process.stderr))
     finally:
         self.io_lock.release()
Exemplo n.º 3
0
 async def launcher(self):
     try:
         while True:
             logger.info("Starting controller %s with command: %s",
                         self.name, self.command)
             try:
                 env = os.environ.copy()
                 env["PYTHONUNBUFFERED"] = "1"
                 self.process = await asyncio.create_subprocess_exec(
                     *shlex.split(self.command),
                     stdout=subprocess.PIPE, stderr=subprocess.PIPE,
                     env=env, start_new_session=True)
                 asyncio.ensure_future(
                     LogParser(self._get_log_source).stream_task(
                         self.process.stdout))
                 asyncio.ensure_future(
                     LogParser(self._get_log_source).stream_task(
                         self.process.stderr))
                 await self._wait_and_ping()
             except FileNotFoundError:
                 logger.warning("Controller %s failed to start", self.name)
             else:
                 logger.warning("Controller %s exited", self.name)
             logger.warning("Restarting in %.1f seconds",
                            self.retry_timer_cur)
             try:
                 await asyncio.wait_for(self.retry_now.wait(),
                                        self.retry_timer_cur)
             except asyncio.TimeoutError:
                 pass
             self.retry_timer_cur *= self.retry_timer_backoff
     except asyncio.CancelledError:
         await self._terminate()