Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What it seems like is you're trying to make/run multiple reactors. Everything gets attached to the <em>same</em> reactor. Here's how to use a <a href="http://twistedmatrix.com/documents/current/core/howto/defer.html#auto8" rel="noreferrer"><code>DeferredList</code></a> to wait for all of your callbacks to finish.</p> <p>Also note that <code>twisAmaz</code> returns a value. That value is passed through the <code>callbacks</code> <code>DeferredList</code> and comes out as <code>value</code>. Since a <code>DeferredList</code> keeps the order of the things that are put into it, you can cross-reference the index of the results with the index of your ISBNs.</p> <pre><code>from twisted.internet import defer def twisAmaz(contents): stonesoup = BeautifulStoneSoup(contents) ret = {} if stonesoup.find("mediumimage") is None: ret['imageurl'] = "/images/notfound.png" else: ret['imageurl'] = stonesoup.find("mediumimage").url.contents[0] ret['usedPdata'] = stonesoup.find("lowestusedprice") ret['newPdata'] = stonesoup.find("lowestnewprice") ret['titledata'] = stonesoup.find("title") ret['reviewdata'] = stonesoup.find("editorialreview") if stonesoup.find("asin") is not None: ret['asin'] = stonesoup.find("asin").contents[0] else: ret['asin'] = 'None' return ret callbacks = [] for tmpISBN in isbn: #Go through ISBN numbers and get Amazon API information for each callbacks.append(getPage(fetchInfo(tmpISBN)).addCallback(twisAmazon)) def printResult(result): for e, (success, value) in enumerate(result): print ('[%r]:' % isbn[e]), if success: print 'Success:', value else: print 'Failure:', value.getErrorMessage() callbacks = defer.DeferredList(callbacks) callbacks.addCallback(printResult) reactor.run() </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload