Toby Dickenson wrote:
Set twisted aside for a moment. I propose one good pythonic interface to your html creation code may be a generate_html_iter() method, which returns an iterator over the documents html fragments. You can implement this using the processNextElement approach you suggested, although python generator functions may be more convenient.
A thin wrapper around this iterator could use reactor.callLater to schedule it, then fire a callback when complete. An equally thin wrapper could use PostMessage to calculate the document in the background of a win32 gui. Or it could feed a pull producer. Alternatively it could be run in another thread with deferToThread(lambda:''.join(g.generate_html_iter()))
I hope this helps,
Some seconds before I read your message I've posted my reply to Christopher Armstrong. This message contains some code of mine that already uses some sort of wrapper class. Though it doesn't use an iterator and maybe isn't as pythonic, it wraps a synchronous interface. Not sure if this is similar to the thin wrapper you had in mind? Thank you very much, Jürgen