A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2007-February/071188.html below:

[Python-Dev] microthreading vs. async io

[Python-Dev] microthreading vs. async io [Python-Dev] microthreading vs. async ioJean-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

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4