Fix the thread index in parallel_debug

This commit is contained in:
Thomas Nagy 2017-02-14 19:42:02 +01:00
parent d7822a04de
commit 620f255b13
No known key found for this signature in database
GPG Key ID: 49B4C67C05277AAA
1 changed files with 23 additions and 5 deletions

View File

@ -12,7 +12,7 @@ a file named pdebug.svg in the source directory::
...
"""
import time, sys, re
import time, sys, re, threading
try: from Queue import Queue
except: from queue import Queue
from waflib import Runner, Options, Utils, Task, Logs, Errors
@ -214,7 +214,7 @@ def process(self):
except KeyError:
pass
self.generator.bld.producer.set_running(1, id(Utils.threading.currentThread()), self)
self.generator.bld.producer.set_running(1, self)
try:
ret = self.run()
@ -242,7 +242,7 @@ def process(self):
if self.hasrun != Task.SUCCESS:
m.error_handler(self)
self.generator.bld.producer.set_running(-1, id(Utils.threading.currentThread()), self)
self.generator.bld.producer.set_running(-1, self)
Task.Task.process_back = Task.Task.process
Task.Task.process = process
@ -260,8 +260,26 @@ def do_start(self):
make_picture(self)
Runner.Parallel.start = do_start
def set_running(self, by, i, tsk):
self.taskinfo.put( (i, id(tsk), time.time(), tsk.__class__.__name__, self.processed, self.count, by) )
lock_running = threading.Lock()
def set_running(self, by, tsk):
with lock_running:
try:
cache = self.lock_cache
except AttributeError:
cache = self.lock_cache = {}
i = 0
if by > 0:
vals = cache.values()
for i in range(self.numjobs):
if i not in vals:
cache[tsk] = i
break
else:
i = cache[tsk]
del cache[tsk]
self.taskinfo.put( (i, id(tsk), time.time(), tsk.__class__.__name__, self.processed, self.count, by) )
Runner.Parallel.set_running = set_running
def name2class(name):