コード例 #1
0
ファイル: run_sandbox_packet.py プロジェクト: cgorbit/rem
    def send_update(update, is_final):
        try:
            return rem_proxy.update_graph(
                opts.task_id,
                rpc_server_addr,
                update,
                is_final
            )

        except Exception as e:
            if isinstance(e, socket.error):
                logging.warning("on_notifier_fail: %s" % e)
            else:
                logging.exception("on_notifier_fail")

            if is_xmlrpc_exception(e, WrongTaskIdError):
                try:
                    on_notifier_fail()
                except:
                    logging.exception("on_notifier_fail")

                raise RuntimeError("Failed to send data to rem server: %s" % e.faultString)

            else:
                # FIXME Actually if isinstance(e, xmlrpclib.Fault) then not retriable
                #       but not fatal as WrongTaskIdError
                raise RemNotifier.RetriableError(str(e))
コード例 #2
0
ファイル: future.py プロジェクト: cgorbit/rem
 def _run_ready(self, to_run):
     future = Future(self)
     for f in to_run:
         try:
             f(future)
         except:
             logging.exception("Failed to future-ready callback")
コード例 #3
0
ファイル: run_sandbox_packet.py プロジェクト: cgorbit/rem
def try_log_descriptors():
    try:
        import subprocess
        files = subprocess.check_output(['lsof', '-p', str(os.getpid())])
    except:
        logging.exception('Failed to dump lsof')
    else:
        logging.debug('lsof\n' + files)
コード例 #4
0
ファイル: run_sandbox_packet.py プロジェクト: cgorbit/rem
    def _the_loop(self):
        next_try_min_time = 0

        while True:
            with self._lock:
                while True:
                    now = time.time()

                    if self._should_stop_max_time:
                        if now > self._should_stop_max_time \
                                or next_try_min_time > self._should_stop_max_time:
                            return

                    if self._pending_update:
                        deadline = next_try_min_time

                        if now > deadline:
                            break

                    else:
                        deadline = None

                    self._changed.wait(deadline - now if deadline is not None else None)

                update, is_final = self._pending_update
                self._pending_update = None

            logging.debug('sending_update: %s' % ((update, is_final),))

            try:
                self._send_update(update, is_final)

            except self.RetriableError:
                logging.exception('Failed to send update')

                with self._lock:
                    if not self._pending_update:
                        self._pending_update = (update, is_final)

                    next_try_min_time = time.time() + self._RETRY_DELAY

            else:
                if is_final:
                    return
コード例 #5
0
ファイル: future.py プロジェクト: cgorbit/rem
 def _run_cancelled(self, to_run):
     for f in to_run:
         try:
             f()
         except:
             logging.exception("Failed to future-cancelled callback")
コード例 #6
0
ファイル: resource_sharing.py プロジェクト: cgorbit/rem
    def _share_loop(self):
        in_progress = set()

        def schedule_retry(job):
            self._schedule_retry(job, self.Action.SHARE_FILE, delay=10.0)

        def _finished(job_id, f):
            T('enter_sky_share_finished %d' % job_id)

            job = self.running[job_id]
            in_progress.remove(job)

            try:
                with Timing('sky_share_future_get %d' % job_id):
                    torrent_id = f.get()
            #except ???Error as e: # TODO
                #pass
            except Exception as e:
                logging.warning('sky share for %s faled: %s' % (job, e))

                # TODO better checks or collect STDERR
                for file in job.files:
                    if not os.path.exists(job.directory + '/' + file):
                        msg = 'Failed to share %s/%s: %s' % (job.directory, job.files, e)
                        self._set_promise_error(job, OSError(errno.ENOENT, msg))
                        return

                schedule_retry(job)
                return

            logging.debug('sky share successfully done for %s: %s' % (job, torrent_id))

            with self.lock:
                job.torrent_id = torrent_id
                self.upload_queue.append(job)
                self.upload_queue_not_empty.notify()

        while not self.should_stop: # TODO
            T('begin_share_loop')

            with self.lock:
                while not(self.should_stop or self.share_queue):
                    self.share_queue_not_empty.wait()

                if self.should_stop: # TODO
                    return

                job = self.share_queue.popleft()
                in_progress.add(job)

            logging.debug('Run sky share for %s' % job)

            try:
                with Timing('sky_share_future %d' % job.id): # ~4ms (we wait pid from subprocsrv)
                    torrent_id = sky_share(self.subproc, job.directory, job.files)
            except:
                logging.exception('') # TODO
                in_progress.remove(job)
                schedule_retry(job)
                del job
                continue

            torrent_id.subscribe(lambda f, job_id=job.id: _finished(job_id, f))

            del torrent_id
            del job
コード例 #7
0
ファイル: run_sandbox_packet.py プロジェクト: cgorbit/rem
def try_guess_my_host(peer_addr, timeout):
    try:
        return guess_my_host(peer_addr, timeout)
    except:
        logging.exception('Failed to guess_my_host')
コード例 #8
0
ファイル: run_sandbox_packet.py プロジェクト: cgorbit/rem
        logging.debug('lsof\n' + files)


if __name__ == '__main__':
    opts = parse_arguments()

    _absolutize_fs_options(opts)

# TODO XXX Pass as it should be
    opts.listen_port = '15000-15999'

    if opts.listen_port is not None:
        try:
            opts.listen_port = _parse_listen_port(opts.listen_port)
        except:
            logging.exception("Failed to parse --listen-port")

    os.chdir(opts.work_dir)

# TODO delayed_executor guard
# TODO rpc_server guard
# TODO rem_notifier guard

    rem.delayed_executor.start()
    #guard = OnDel(rem.delayed_executor.stop)

    if opts.snapshot_file is not None:
        with open(opts.snapshot_file) as snap:
            pck = pickle.load(snap)
    else:
        pck = pickle.loads(base64.b64decode(opts.snapshot_data))