[Twisted-Python] Re: Converting async to sync code (blocking until deferreds fire)

Martin Geisler mg at daimi.au.dk
Mon Jul 21 05:05:53 MDT 2008


Jack Whitham <jack-tp at cs.york.ac.uk> writes:

Hello!

> What is the best way to convert asynchronous code (non-blocking,
> returning deferreds) to synchronous code (blocking)?
>
> I have a client that is written using Twisted. Most of the methods
> within the client object return Deferreds because they send messages
> to a server and replies may take some time. This is ideal for the
> wxwidgets GUI that was originally intended to use the client. But
> now I want to write test scripts for the server that are
> synchronous.

You mention Trial below and I think using it is both the easies and
the most correct way to test code using Deferreds.

You simply return your Deferred from your test case and Trial waits on
it to determine if the test passed or failed.

I like this tutorial for Trial: http://ln-s.net/24:F

-- 
Martin Geisler

VIFF (Virtual Ideal Functionality Framework) brings easy and efficient
SMPC (Secure Multi-Party Computation) to Python. See: http://viff.dk/.





More information about the Twisted-Python mailing list