[Twisted-Python] Running CPU bound function concurrently in twisted

Glyph glyph at twistedmatrix.com
Mon Jun 24 22:08:27 MDT 2019



> On Jun 24, 2019, at 4:26 PM, Chengi Liu <chengi.liu.86 at gmail.com> wrote:
> 
>              t = defer.ensureDeferred(network_get(i))

The meaning of "ensureDeferred" is, "ensure [that this thing, which may be a coroutine or Deferred, is a] Deferred".  You don't need to use it with things decorated with @inlineCallbacks, only with `async def`; it does nothing in your example.

We should really have a more explicit version of this, like a classmethod, Deferred.fromCoroutine(), that makes more sense in terms of what context you need to use it in.  (The naming here comes from asyncio.ensure_future, but that does have the somewhat more explicit loop.create_task to pair with it.)

-glyph

-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20190624/bd43a02e/attachment-0002.html>


More information about the Twisted-Python mailing list