[Python-Dev] microthreading vs. async io (original) (raw)

Jean-Paul Calderone exarkun at divmod.com
Thu Feb 15 17:47:27 CET 2007


On Thu, 15 Feb 2007 10:36:21 -0600, dustin at v.igoro.us wrote:

[snip]

def fetchSequence(...): fetcher = Fetcher() yield fetcher.fetchHomepage() firstData = yield fetcher.fetchPage('http://...') if someCondition(firstData): while True: secondData = yield fetcher.fetchPage('http://...') # ... if someOtherCondition(secondData): break else: # ...

Ahem:

from twisted.internet import reactor
from twisted.internet.defer import inlineCallbacks
from twisted.web.client importt getPage

@inlineCallbacks
def fetchSequence(...):
    homepage = yield getPage(homepage)
    firstData = yield getPage(anotherPage)
    if someCondition(firstData):
        while:
            secondData = yield getPage(wherever)
            if someOtherCondition(secondData):
                break
    else:
        ...

So as I pointed out in another message in this thread, for several years it has been possible to do this with Twisted. Since Python 2.5, you can do it exactly as I have written above, which looks exactly the same as your example code.

Is the only problem here that this style of development hasn't had been made visible enough?

Jean-Paul



More information about the Python-Dev mailing list