O'Reilly logo

Python Parallel Programming Cookbook by Giancarlo Zaccone

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Dealing with Asyncio and Futures

Another key component of the Asyncio module is the Future class. This is very similar to concurrent.futures.Futures, but of course, it is adapted in the main mechanism of Asyncio's event loop. The asyncio.Future class represents a result (but can also be an exception) that is not yet available. It therefore represents an abstraction of something that is yet to be accomplished.

Callbacks that have to process any results are in fact added to the instances of this class.

Getting ready

To manage an object Future in Asyncio, we must declare the following:

import asyncio
future = asyncio.Future()

The basic methods of this class are:

  • cancel(): This cancels the future and schedules callbacks
  • result(): This returns the result ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required