Esempio n. 1
0
def expensive_as_string(item):
    time.sleep(0.01)
    return str(item)


def multi_expensive_as_string(start, end):
    return ",".join([expensive_as_string(item) for item in items[start:end]])


if __name__ == "__main__":

    # Needs to be called only once for lifetime of process
    initialize()

    # Example 1: trivial (and slightly pointless) usage
    task = Task()

    task.run(as_string, 2000)

    # Example 2: divide job optimally using ranges function
    #task = Task()
    #for start, end in ranges(items):
    # Note we don't pass items because pickling is expensive and defeats
    # the purpose of the exercize.
    #   task.run(multi_expensive_as_string, start, end)
    # print(", ".join(task.get()))

    # Stop the multicore workers
    shutdown()
Esempio n. 2
0
 def setUp(self):
     super(TaskTestCase, self).setUp()
     shutdown()
Esempio n. 3
0
 def tearDown(self):
     super(TaskTestCase, self).tearDown()
     shutdown()
Esempio n. 4
0
 def tearDownClass(cls):
     super(TaskTestCase, cls).tearDownClass()
     shutdown()