Beispiel #1
0
def job_cycle(outqueue, jobid, target, args, kwargs):

  try:
    value = target( *args, **kwargs )

  except Exception, e:
    res = result.error( exception = e, traceback = result.get_traceback_info() )
Beispiel #2
0
def job_cycle(outqueue, jobid, target, args, kwargs):

    try:
        value = target(*args, **kwargs)

    except Exception as e:
        res = result.error(exception=e, traceback=result.get_traceback_info())

    else:
        res = result.success(value=value)

    outqueue.put((jobid, res))
Beispiel #3
0
def pool_process_cycle(
    pid,
    inqueue,
    outqueue,
    waittime,
    lifecycle,
    termination_signal,
    idle_timeout,
):

    controller = lifecycle()
    outqueue.put((worker_startup_event, pid))
    last_activity = time.time()

    while controller.active():
        if last_activity + idle_timeout < time.time():
            outqueue.put((worker_termination_event, pid))
            break

        try:
            data = inqueue.get(timeout=waittime)

        except Empty:
            continue

        if data == termination_signal:
            outqueue.put((worker_shutdown_event, pid))
            break

        assert len(data) == 4
        (jobid, target, args, kwargs) = data
        outqueue.put((job_started_event, (jobid, pid)))
        controller.record_job_start()

        try:
            value = target(*args, **kwargs)

        except Exception as e:
            res = result.error(exception=e,
                               traceback=result.get_traceback_info())

        else:
            res = result.success(value=value)

        outqueue.put((job_finished_event, (jobid, pid, res)))
        controller.record_job_end()
        last_activity = time.time()

    else:
        outqueue.put((worker_termination_event, pid))
Beispiel #4
0
  def poll(self):

    if self.outqueue:
      ( jobid, target, args, kwargs ) = self.outqueue.popleft()

      try:
        value = target( *args, **kwargs )

      except Exception, e:
        res = result.error( exception = e, traceback = result.get_traceback_info() )

      else:
        res = result.success( value = value )

      self.inqueue.append( ( jobid, res ) )
Beispiel #5
0
    def poll(self):

        if self.outqueue:
            (jobid, target, args, kwargs) = self.outqueue.popleft()

            try:
                value = target(*args, **kwargs)

            except Exception, e:
                res = result.error(exception=e,
                                   traceback=result.get_traceback_info())

            else:
                res = result.success(value=value)

            self.inqueue.append((jobid, res))
Beispiel #6
0
def pool_process_cycle(
  pid,
  inqueue,
  outqueue,
  waittime,
  lifecycle,
  termination_signal,
  idle_timeout,
  ):

  controller = lifecycle()
  outqueue.put( ( worker_startup_event, pid ) )
  last_activity = time.time()

  while controller.active():
    if last_activity + idle_timeout < time.time():
      outqueue.put( ( worker_termination_event, pid ) )
      break

    try:
      data = inqueue.get( timeout = waittime )

    except Empty:
      continue

    if data == termination_signal:
      outqueue.put( ( worker_shutdown_event, pid ) )
      break

    assert len( data ) == 4
    ( jobid, target, args, kwargs ) = data
    outqueue.put( ( job_started_event, ( jobid, pid ) ) )
    controller.record_job_start()

    try:
      value = target( *args, **kwargs )

    except Exception, e:
      res = result.error( exception = e, traceback = result.get_traceback_info() )

    else:
      res = result.success( value = value )

    outqueue.put( ( job_finished_event, ( jobid, pid, res ) ) )
    controller.record_job_end()
    last_activity = time.time()