[Twisted-Python] Mimicking a blocking API using Twisted

Glyph glyph at twistedmatrix.com
Sun Mar 25 19:23:46 MDT 2012


On Mar 25, 2012, at 8:03 PM, Itamar Turner-Trauring wrote:

> On 03/25/2012 07:54 PM, Laurens Van Houtven wrote:
>> The thing I'm documenting is a server, I'm documenting it by interacting with it as a client. I realize that doesn't entirely detract from your point -- you might still be introducing problems that would not affect a "real" client.
>> 
>> My intention is to write BDD-ish stuff (except not with the usual cucumber-style scenario text).
> 
> This might be workable if the protocol is synchronous: send request, get 
> back response. This wouldn't work e.g. for a chat protocol. I bet you 
> could do something horrible where the doctest gets wrapped in an 
> inlineCallbacks wrapper, and then you can yield Deferreds.

You can also just call back the relevant deferreds synchronously within your doctest, and print things when they fire.  Given that your doctests will have to explicitly specify the response events being fired anyway, this is probably the best way to go.

-glyph



More information about the Twisted-Python mailing list