Revision 0aeeb6e3 lib/jqueue.py

b/lib/jqueue.py
1137 1137
    queue = job.queue
1138 1138
    assert queue == self.pool.queue
1139 1139

  
1140
    self.SetTaskName("Job%s" % job.id)
1140
    setname_fn = lambda op: self.SetTaskName(self._GetWorkerName(job, op))
1141
    setname_fn(None)
1141 1142

  
1142 1143
    proc = mcpu.Processor(queue.context, job.id)
1143 1144

  
1144
    if not _JobProcessor(queue, proc.ExecOpCode, job)():
1145
    # Create wrapper for setting thread name
1146
    wrap_execop_fn = compat.partial(self._WrapExecOpCode, setname_fn,
1147
                                    proc.ExecOpCode)
1148

  
1149
    if not _JobProcessor(queue, wrap_execop_fn, job)():
1145 1150
      # Schedule again
1146 1151
      raise workerpool.DeferTask(priority=job.CalcPriority())
1147 1152

  
1153
  @staticmethod
1154
  def _WrapExecOpCode(setname_fn, execop_fn, op, *args, **kwargs):
1155
    """Updates the worker thread name to include a short summary of the opcode.
1156

  
1157
    @param setname_fn: Callable setting worker thread name
1158
    @param execop_fn: Callable for executing opcode (usually
1159
                      L{mcpu.Processor.ExecOpCode})
1160

  
1161
    """
1162
    setname_fn(op)
1163
    try:
1164
      return execop_fn(op, *args, **kwargs)
1165
    finally:
1166
      setname_fn(None)
1167

  
1168
  @staticmethod
1169
  def _GetWorkerName(job, op):
1170
    """Sets the worker thread name.
1171

  
1172
    @type job: L{_QueuedJob}
1173
    @type op: L{opcodes.OpCode}
1174

  
1175
    """
1176
    parts = ["Job%s" % job.id]
1177

  
1178
    if op:
1179
      parts.append(op.TinySummary())
1180

  
1181
    return "/".join(parts)
1182

  
1148 1183

  
1149 1184
class _JobQueueWorkerPool(workerpool.WorkerPool):
1150 1185
  """Simple class implementing a job-processing workerpool.
1151 1186

  
1152 1187
  """
1153 1188
  def __init__(self, queue):
1154
    super(_JobQueueWorkerPool, self).__init__("JobQueue",
1189
    super(_JobQueueWorkerPool, self).__init__("Jq",
1155 1190
                                              JOBQUEUE_THREADS,
1156 1191
                                              _JobQueueWorker)
1157 1192
    self.queue = queue

Also available in: Unified diff