Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You're already doing it... sort of.</p> <p>Your problem here is that <code>time.sleep()</code> is a blocking call, and will therefore make your whole server stop.</p> <p>If you're using that as a stand-in for something that does network I/O (like <code>urllib</code>), the best option is usually to do the I/O with Twisted (like <code>twisted.web.client.getPage</code>) rather than to try to do something to the blocking code. Twisted has lots of client libraries. These libraries will generally give you a <code>Deferred</code>, which you're already handling.</p> <p>If you're using it as a stand-in for actually waiting, then you can create a <code>Deferred</code> which waits with <a href="http://twistedmatrix.com/documents/11.0.0/api/twisted.internet.task.deferLater.html" rel="nofollow"><code>deferLater</code></a>.</p> <p>If you're using it as a stand-in for something CPU intensive that doesn't grab the GIL (like PIL image encoding, or a native XML parser), or an existing native / proprietary I/O layer (like Oracle or MSSQL database bindings) that you'd prefer not to rewrite to use Twisted properly, you can invoke it with <a href="http://twistedmatrix.com/documents/11.0.0/api/twisted.internet.threads.deferToThread.html" rel="nofollow"><code>deferToThread</code></a>.</p> <p>However you get your <code>Deferred</code>, you're almost set up to handle it. You just need to adjust <code>say_hi</code> to return one:</p> <pre><code>def say_hi(self, req): req.setHeader("content-type", "text/html") d = getADeferredSomehow() def done(result): req.write("hello!") req.finish() return d.addBoth(done) </code></pre>
    singulars
    1. This table or related slice is empty.
    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. 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.
 

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