Example #1
0
    def perform(self, procedure, args=(), kwargs={}, timelimit=True):
        """This method allow the robot to perform an action. It create one thread for the current action and check if this thread is allow to run

        Args:
            procedure (function): The desired action procedure
            args (tuple, optional): The procedure arguments. Defaults to ().
            kwargs (dict, optional): The procedure kwargs . Defaults to {}.
            timelimit (bool, optional): The match time limit. Defaults to True.

        Returns:
            Thread : Return the created thread
        """
        thread = Thread(args=args, kwargs=kwargs, daemon=True)
        thread_id = id(thread)

        def target(*args, **kwargs):
            try:
                output = procedure(*args, **kwargs)
                self.outputs[thread_id] = output
            except AccessDenied:
                self.outputs[thread_id] = None
            except:
                self.outputs[thread_id] = None
                raise
            finally:
                if thread_id in self.blacklist:
                    self.blacklist.remove(thread_id)
                if thread_id in self.whitelist:
                    self.whitelist.remove(thread_id)

        if not timelimit:
            self.whitelist.add(thread_id)
        thread._target = target
        thread.start()
        return thread
Example #2
0
def main(tokens: set):
    queue = Queue()
    threads = []

    for token in tokens:
        queue.put_nowait(token)

    for _ in range(THREADS):
        thread = Thread()
        threads.append(thread)

        thread._target = bound_get_diff
        thread._args = (queue, )

        thread.start()

    for thread in threads:
        thread.join()
Example #3
0
    def perform(self, procedure, args=(), kwargs={}, timelimit=True):
        thread = Thread(args=args, kwargs=kwargs, daemon=True)
        thread_id = id(thread)

        def target(*args, **kwargs):
            try:
                output = procedure(*args, **kwargs)
                self.outputs[thread_id] = output
            except AccessDenied:
                self.outputs[thread_id] = None
            except:
                self.outputs[thread_id] = None
                raise
            finally:
                if thread_id in self.manager.blacklist:
                    self.manager.blacklist.remove(thread_id)
                if thread_id in self.manager.whitelist:
                    self.manager.whitelist.remove(thread_id)

        if not timelimit: self.manager.whitelist.add(thread_id)
        thread._target = target
        thread.start()
        return thread
Example #4
0
                    print(nextline)
            else:
                break


def run():
    monitor()  #start the monitor routine
    scheduler = BlockingScheduler()

    scheduler.add_job(monitor, 'interval', minutes=int(
        config.updatetime))  #add monitor to blocking scheduler

    scheduler.start()


if __name__ == "__main__":
    root = tk.Tk()
    root.title('YTCM GUI')
    root.geometry('{}x{}'.format(800, 500))
    root.configure(bg=config.bgcolor)

    main = MainWindow(root)
    fname = config.serverdir + config.statuslog

    if config.standalone == True:
        t._target = run
        t.daemon = True
        t.start()

    root.mainloop()