Пример #1
0
    def testJoiningAWorkerWaitsUntilWorkIsDone(self):
        global workDone

        workDone = False

        def sleepOneSecondAndSetWorkDoneToTrue():
            global workDone
            sleep(0.1)
            workDone = True

        Worker.call(sleepOneSecondAndSetWorkDoneToTrue).asDaemon.start().join()

        self.assertTrue(workDone)
Пример #2
0
    def testIfWorkerThreadIsNotSetDaemonThenCallsFunctionsInANonDaemonThread(
            self):
        global workerThreadIsDaemon

        workerThreadIsDaemon = False

        def setWorkerThreadIsDaemon():
            global workerThreadIsDaemon
            workerThreadIsDaemon = current_thread().isDaemon()

        Worker.call(setWorkerThreadIsDaemon).start().join()

        self.assertFalse(workerThreadIsDaemon)
Пример #3
0
    def testWorkerCallsFunctionsInAnotherThread(self):
        global workerThread

        workerThread = None

        def setworkerThread():
            global workerThread
            workerThread = current_thread()

        Worker.call(setworkerThread).asDaemon.start().join()

        self.assertIsNotNone(workerThread)
        self.assertFalse(current_thread() == workerThread)
Пример #4
0
    def testWorkerCallsFunctionsWithNoParameters(self):
        global functionWasCalled

        functionWasCalled = False

        def setFunctionWasCalledToTrue():
            global functionWasCalled
            functionWasCalled = True

        self.assertFalse(functionWasCalled)

        Worker.call(setFunctionWasCalledToTrue).asDaemon.start().join()

        self.assertTrue(functionWasCalled)
Пример #5
0
    def testWorkerCallsFunctionsWithPassedParameters(self):
        global functionWasCalled

        functionWasCalled = False

        def setFunctionWasCalledTo(boolean):
            global functionWasCalled
            functionWasCalled = boolean

        self.assertFalse(functionWasCalled)

        Worker.call(setFunctionWasCalledTo).withArgs(
            True).asDaemon.start().join()

        self.assertTrue(functionWasCalled)
Пример #6
0
    def start(self):
        self._thread = threading.Timer(self._repeatInterval,
                                       function=self._loop)
        self._thread.daemon = self._isDaemon
        self._thread.start()

        firstLoopWorker = Worker.call(
            self._function).withArgs(*self._arguments)
        firstLoopWorker._isDaemon = self._isDaemon
        firstLoopWorker.start()

        return self
Пример #7
0
    def testIfWorkerIsSetAsDaemonThenCallsFunctionsInADaemonThread(self):
        global workerThreadIsDaemon

        workerThreadIsDaemon = False

        def setWorkerThreadIsDaemon():
            global workerThreadIsDaemon
            workerThreadIsDaemon = current_thread().isDaemon()

        worker = Worker.call(setWorkerThreadIsDaemon).asDaemon.start()

        worker.join()

        self.assertTrue(workerThreadIsDaemon)
Пример #8
0
 def startGameRoutine(self):
     Worker.call(self.gameRoutine).asDaemon.start()
Пример #9
0
    def testWorkerKnowsWhenItIsWorking(self):
        worker = Worker.call(sleep).withArgs(0.1).asDaemon.start()

        self.assertTrue(worker.isWorking())