User:WindBOT/CoreSource: Difference between revisions

Jump to navigation Jump to search
m
Backported changes from tf wiki windbot
(Backported changes from tf wiki)
m (Backported changes from tf wiki windbot)
Line 22: Line 22:
import tempfile
import tempfile
import traceback
import traceback
import threading
import random
import random
import subprocess
import subprocess
Line 82: Line 83:
kw = kwargs or self.kwargs
kw = kwargs or self.kwargs
return self.func(*(self.pending + args), **kw)
return self.func(*(self.pending + args), **kw)
class BatchScheduler:
def __init__(self, concurrency=16):
self.concurrency = 16
self.tasks = []
def schedule(self, target, *args, **kwargs):
self.tasks.append((target, args, kwargs))
def execute(self):
while len(self.tasks):
pool = []
numThreads = min(self.concurrency, len(self.tasks))
for task in range(numThreads):
task = self.tasks[task]
t = threading.Thread(target=task[0], args=task[1], kwargs=task[2])
t.start()
pool.append(t)
for t in pool:
t.join()
self.tasks = self.tasks[numThreads:]
def getTempFilename():
def getTempFilename():
global config
global config

Navigation menu