def test_old_api_support(self): """ For now, the request_rewrite supports the old interface, too. """ def someWork(destination=None): if destination is None: destination = [""] time.sleep(0.001) destination[0] = "Hello," return destination callback_result = [ [] ] def callback(result): callback_result[0] = result[0] def test(s, destination=None,): req = Request(someWork) req.onFinish(callback) s2 = req.wait()[0] time.sleep(0.001) if destination is None: destination = [""] destination[0] = s2 + s return destination req = Request( partial(test, s = " World!") ) preAllocatedResult = [""] req.writeInto(preAllocatedResult) req.notify(callback) # Wait for the result assert req.wait()[0] == "Hello, World!" # Wait for it assert callback_result[0] == "Hello, World!" # From the callback assert preAllocatedResult[0] == req.wait()[0], "This might fail if the request was started BEFORE writeInto() was called" requests = [] for i in range(10): req = Request( partial(test, s = "hallo %d" %i) ) requests.append(req) for r in requests: r.wait()