예제 #1
0
    def showEvent(self, event: QtGui.QShowEvent) -> None:

        if "domains" in self.setting.childGroups():
            self.setting.beginGroup("domains")
            self.domains = self.setting.childKeys()
            self.setting.endGroup()
        if not self.domains:
            self.domains = configurations.get("domains")

        if not self.updating and self.domains:
            self.updating = True

            self.ui.listWidget.clear()
            if hasattr(self.parent(), "resetParsedDomains"):
                self.parent().resetParsedDomains()
            itemSize = QtCore.QSize(
                self.ui.listWidget.width() -
                self.ui.listWidget.autoScrollMargin() * 2, 50)
            no = 0
            for domain in self.domains:
                item = QtWidgets.QListWidgetItem()
                item.setSizeHint(itemSize)
                item.setData(QtWidgets.QListWidgetItem.UserType, domain)
                widget = self.makeDomainItemWidget(no, domain)
                self.ui.listWidget.addItem(item)
                self.ui.listWidget.setItemWidget(item, widget)
                no += 1

            self.worker = WorkerThread(self.domains)
            self.worker.signal.connect(self.process)
            self.worker.start()
예제 #2
0
def main(workers=10):
    """
    Executes main function of mini-framework's Control thread.
    :param workers: Integer detailing number of worker FIFO threads to employ
    """
    start_logging()
    log_info("New multiprocessing session with {} workers".format(workers))

    # Input JoinableQueue and Output Queue
    inq = JoinableQueue(maxsize=int(workers * 1.5))
    outq = Queue(maxsize=int(workers * 1.5))

    ot = OutThread(workers, outq)
    ot.start()

    for _ in range(workers):
        w = WorkerThread(inq, outq)
        w.start()

    # Create a sequence of a 1000 random alphabetic characters
    random_chars = (ascii_letters[randint(0, 51)] for _ in range(1000))

    # Keep input queue loaded for as long as possible
    # Feed the process pool with work units
    for work in enumerate(random_chars):
        inq.put(work)

    # Fill the input queue with Nones to shut the worker threads down
    # which terminates the process pool
    for _ in range(workers):
        inq.put(None)

    inq.join()
    print("Control process terminating")
예제 #3
0
def main(workers=WORKERS):
    """
    Executes main function of mini-framework's Control thread.
    :param workers: Integer detailing number of worker FIFO threads to employ
    """
    log_info("New mini-framework session with {} workers".format(workers))

    inq = Queue(maxsize=int(workers * 1.5))
    outq = Queue(maxsize=int(workers * 1.5))

    ot = OutThread(workers, outq)
    ot.start()

    for _ in range(workers):
        w = WorkerThread(inq, outq)
        w.start()

    # Create a sequence of a 1000 random alphabetic characters
    random_chars = (ascii_letters[randint(0, 51)] for _ in range(1000))

    # Keep input queue loaded for as long as possible
    for work in enumerate(random_chars):
        inq.put(work)

    # Fill the input queue with Nones to shut the worker threads down
    for _ in range(workers):
        inq.put(None)

    inq.join()
    print("Control thread terminating")
    log_info("Mini-framework finished. Len: {} chars".format(len(ot.output)))
예제 #4
0
    def startDaemon(self):
        """
			Start the thread that takes care of polling and scheduling for all the transports
		"""
        from worker import WorkerThread
        self.thread = WorkerThread(self.name, self.txqueue, self.rxqueue)
        self.thread.start()
예제 #5
0
    def __init__(self, *args, **kwargs):

        if kwargs is not None:
            if 'count' in kwargs:
                self._wcnt = kwargs['count']
            else:
                self._wcnt = WorkerPool.DEFAULT_WORKER_COUNT

            if 'all_done' in kwargs:
                self._all_done = kwargs['all_done']
            else:

                def ___pass(*args, **kwargs):
                    pass

                self._all_done = ___pass
            if 'tick' in kwargs:
                self._tick = kwargs['tick']

        self._wpol = list([])  # all workers
        self._wbsy = dict({})  # busy
        self._wfre = list([])  # free
        self._tque = list([])  # task queue

        self._tick = WorkerPool.DEFAULT_TICK  # sleep time if all busy

        self._wrkr = SchedulerThread(0)  # task schedule is worker

        self._task = Task()  # taks for scheduler
        self._task.target = self._task_schedule
        self._task.args = tuple()
        self._task.kwargs = dict()
        self._ball_done = False

        def _on_worker_task_done(worker):
            """
            default calback for scheduler
            when some worker is done with a task
            it is appended to free workers queue
            also marked free in busy dict 
            """
            self._wfre.append(worker)
            self._wbsy[worker._id] = False

        self.____f = _on_worker_task_done

        # pool initialization

        for i in xrange(1, self._wcnt + 1):
            w = WorkerThread(i)
            w._pool = self  # back reference
            w._worker_task_done = self.____f
            self._wpol.append(w)
            self._wfre.append(w)
            self._wbsy[i] = False

        self._wrkr._target = self._task_schedule
        self._wrkr._args = tuple()
        self._wrkr._kwargs = dict()
예제 #6
0
파일: Engine.py 프로젝트: cristivlas/fisher
 def __init__(self, dispatch, resume=True):
     self.__dispatch = dispatch
     self.__worker = WorkerThread()
     self.hist = [Position(initial, 0, (True, True), (True, True), 0, 0)]
     self.board = chess.Board()
     self.redo = []
     self.searcher = Searcher()
     self.store = DictStore('fisher.dat')
     if resume:
         self.load_game()
예제 #7
0
파일: gui.py 프로젝트: JoselleAstrid/fgx-re
    def run_worker_job(self, job_func):
        if not self.worker_thread:
            # Create a thread.
            # Must store a reference to the thread in a non-local variable,
            # so the thread doesn't get garbage collected after returning
            # from this method
            # https://stackoverflow.com/a/15702922/
            self.worker_thread = WorkerThread()

        # This will emit 'started' and start running the thread
        self.worker_thread.run_job(job_func)
예제 #8
0
    def start_server(self):

        # Check if directory 'www' exists
        self.check_directory()

        while True:

            # Wait for a connection
            conn, addr = self.s.accept()

            # Create a new thread for each connection
            new_thread = WorkerThread(addr, conn, self.dictionary, self.mutex,
                                      self.directory)
            new_thread.start()
예제 #9
0
def run_server(addr, port):
    global task
    log = Log(__name__, level='INFO')
    log.info('Run httpd server until ctrl-c input')

    def shutdown(task):
        task.worker.stop()
        task.running = False

    def start(httpd, id):
        httpd.start()

    def signal_handler(signum, stack):
        log.info('Sending shutdown to httpd server')
        thread.start_new_thread(shutdown, (task, ))

    signal.signal(signal.SIGINT, signal_handler)
    server = Httpd(port=int(port), address=addr)
    task = WorkerThread(server, 'httpd')
    worker = WorkerTasks(tasks=[task], func=start)
    worker.run()
    worker.wait_for_completion(timeout_sec=-1)  # run forever
예제 #10
0
def run():
    WORKERS = 10

    inq = Queue(maxsize=int(WORKERS * 1.5))
    outq = Queue(maxsize=int(WORKERS * 1.5))

    ot = OutThread(WORKERS, outq)
    ot.start()

    for i in range(WORKERS):
        w = WorkerThread(inq, outq)
        w.start()

    # generate a random string of alphabetic characters of length one thousand
    instring = (''.join(
        random.choice(string.ascii_letters) for i in range(1000)))

    for work in enumerate(instring):
        inq.put(work)
    for i in range(WORKERS):
        inq.put(None)
    inq.join()
    print("Control thread terminating")
import os
import urllib
import json
import random
import re
import time
from urllib.parse import urlparse

from config import config
from worker import WorkerThread, WorkerItemStatus
from server import app
from db import db
import statistics
from sample_bots import sample_bots

worker = WorkerThread()
worker.daemon = True
worker.start()


def run_commands(working_dir, commands):
    output = []

    for command in commands:
        print(command)
        output.append('-' * 80)
        output.append(working_dir + '> ' + ' '.join(command))

        result = subprocess.run(command,
                                stdout=subprocess.PIPE,
                                stderr=subprocess.STDOUT,
예제 #12
0
 def test_simple_creation_equality(self):
     wrk1 = WorkerThread('hello')
     wrk2 = WorkerThread('hello')
     self.assertEqual(wrk1._id, wrk2._id)
예제 #13
0
control.py: Creates queues, starts output and worker threads,
            and pushes inputs into the input queue.
"""
from multiprocessing import Queue, JoinableQueue
from output import OutThread
from worker import WorkerThread
from random import choice
from string import ascii_letters
if __name__ == '__main__':
    WORKERS = 10

    inq = JoinableQueue(maxsize=int(WORKERS * 1.5))
    outq = Queue(maxsize=int(WORKERS * 1.5))

    ot = OutThread(WORKERS, outq)
    ot.start()

    for i in range(WORKERS):
        w = WorkerThread(inq, outq)
        w.start()

    instring = ''
    for i in range(1000):
        instring += choice(ascii_letters)
    for work in enumerate(instring):
        inq.put(work)
    for i in range(WORKERS):
        inq.put(None)
    inq.join()
    print("Control thread terminating")