示例#1
0
 def testClose(self):
     with Pool() as p:
         for i in range(Pyro4.config.THREADPOOL_SIZE):
             p.process(Job(str(i + 1)))
     with self.assertRaises(PoolError):
         p.process(Job(1))  # must not allow new jobs after closing
     self.assertEqual(0, len(p.busy))
     self.assertEqual(0, len(p.idle))
示例#2
0
 def testAllBusy(self):
     try:
         Pyro4.config.COMMTIMEOUT = 0.2
         with Pool() as p:
             for i in range(Pyro4.config.THREADPOOL_SIZE):
                 p.process(SlowJob(str(i + 1)))
             # putting one more than the number of workers should raise an error:
             with self.assertRaises(NoFreeWorkersError):
                 p.process(SlowJob("toomuch"))
     finally:
         Pyro4.config.COMMTIMEOUT = 0.0
示例#3
0
    def testMany(self):
        class Job2(object):
            def __init__(self, name="unnamed"):
                self.name = name

            def __call__(self):
                time.sleep(0.01)

        with Pool() as p:
            for i in range(1 + Pyro4.config.THREADPOOL_SIZE * 100):
                p.process(Job2(str(i)))
            time.sleep(2)
            self.assertEqual(0, p.num_jobs(),
                             "queue must be finished in under two seconds")
示例#4
0
 def testClose(self):
     # test that after closing a job queue, no more new jobs are taken from the queue, and some other stuff
     with Pool() as p:
         for i in range(Pyro4.config.THREADPOOL_SIZE):
             p.process(Job(str(i + 1)))
     with self.assertRaises(PoolError):
         p.process(Job(1))  # must not allow new jobs after closing
     self.assertTrue(p.waiting_jobs() > 1)
     time.sleep(JOB_TIME * 1.1)
     jobs_left = p.waiting_jobs()
     time.sleep(
         JOB_TIME * 1.1
     )  # wait till jobs finish and a new one *might* be taken off the queue
     self.assertEqual(jobs_left, p.waiting_jobs(),
                      "may not process new jobs after close")
示例#5
0
 def testScaling(self):
     with Pool() as p:
         for i in range(Pyro4.config.THREADPOOL_SIZE_MIN - 1):
             p.process(Job("x"))
         self.assertEqual(1, len(p.idle))
         self.assertEqual(Pyro4.config.THREADPOOL_SIZE_MIN - 1, len(p.busy))
         p.process(Job("x"))
         self.assertEqual(0, len(p.idle))
         self.assertEqual(Pyro4.config.THREADPOOL_SIZE_MIN, len(p.busy))
         # grow until no more free workers
         while True:
             try:
                 p.process(Job("x"))
             except NoFreeWorkersError:
                 break
         self.assertEqual(0, len(p.idle))
         self.assertEqual(Pyro4.config.THREADPOOL_SIZE, len(p.busy))
         # wait till jobs are done and check ending situation
         time.sleep(JOB_TIME * 1.5)
         self.assertEqual(0, len(p.busy))
         self.assertEqual(Pyro4.config.THREADPOOL_SIZE_MIN, len(p.idle))
示例#6
0
    def testThreadpoolQueue(self):
        class Job2(object):
            def __init__(self, name="unnamed"):
                self.name = name

            def __call__(self):
                time.sleep(0.7)

        try:
            Pyro4.config.THREADPOOL_ALLOW_QUEUE = True
            Pyro4.config.COMMTIMEOUT = 0.1
            with Pool() as p:
                for i in range(1 + Pyro4.config.THREADPOOL_SIZE * 2):
                    p.process(Job2(str(i)))
                time.sleep(2)
                self.assertEqual(
                    0, p.waiting_jobs(),
                    "queue must be finished in under two seconds")
        finally:
            Pyro4.config.THREADPOOL_ALLOW_QUEUE = False
            Pyro4.config.COMMTIMEOUT = 0
示例#7
0
 def testSingle(self):
     with Pool() as p:
         job = Job()
         p.process(job)
         time.sleep(0.02)  # let it pick up the job
         self.assertEqual(1, len(p.busy))
示例#8
0
 def testCreate(self):
     with Pool() as jq:
         _ = repr(jq)
     self.assertTrue(jq.closed)
示例#9
0
 def testSingle(self):
     with Pool() as p:
         job = Job()
         p.process(job)
         time.sleep(0.02)  # let it pick up the job
         self.assertEqual(0, p.num_jobs())