• Complain

Caleb Hattingh - Using Asyncio in Python 3

Here you can read online Caleb Hattingh - Using Asyncio in Python 3 full text of the book (entire story) in english for free. Download pdf and epub, get meaning, cover and reviews about this ebook. year: 2018, publisher: OReilly Media, Inc., genre: Home and family. Description of the work, (preface) as well as reviews are available. Best literature library LitArk.com created for fans of good reading and offers a wide selection of genres:

Romance novel Science fiction Adventure Detective Science History Home and family Prose Art Politics Computer Non-fiction Religion Business Children Humor

Choose a favorite category and find really read worthwhile books. Enjoy immersion in the world of imagination, feel the emotions of the characters or learn something new for yourself, make an fascinating discovery.

Caleb Hattingh Using Asyncio in Python 3
  • Book:
    Using Asyncio in Python 3
  • Author:
  • Publisher:
    OReilly Media, Inc.
  • Genre:
  • Year:
    2018
  • Rating:
    5 / 5
  • Favourites:
    Add to favourites
  • Your mark:
    • 100
    • 1
    • 2
    • 3
    • 4
    • 5

Using Asyncio in Python 3: summary, description and annotation

We offer to read an annotation, description, summary or preface (depends on what the author of the book "Using Asyncio in Python 3" wrote himself). If you haven't found the necessary information about the book — write in the comments, we will try to find it.

Caleb Hattingh: author's other books


Who wrote Using Asyncio in Python 3? Find out the surname, the name of the author of the book and a list of all author's works by series.

Using Asyncio in Python 3 — read online for free the complete book (whole text) full work

Below is the text of the book, divided by pages. System saving the place of the last page read, allows you to conveniently read the book "Using Asyncio in Python 3" online for free, without having to search again every time where you left off. Put a bookmark, and you can go to the page where you finished reading at any time.

Light

Font size:

Reset

Interval:

Bookmark:

Make
Using Asyncio in Python 3

by Caleb Hattingh

Copyright 2018 OReilly Media, Inc. All rights reserved.

Printed in the United States of America.

Published by OReilly Media, Inc. , 1005 Gravenstein Highway North, Sebastopol, CA 95472.

OReilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://oreilly.com/safari). For more information, contact our corporate/institutional sales department: 800-998-9938 or corporate@oreilly.com .

  • Editors: Jeff Bleiel and Susan Conant
  • Production Editor: Nicholas Adams
  • Copyeditor: Dwight Ramsey
  • Interior Designer: David Futato
  • Cover Designer: Karen Montgomery
  • Illustrator: Rebecca Demarest
  • Tech Reviewer: Yury Selivanov
  • March 2018: First Edition
Revision History for the First Edition
  • 2018-03-08: First Release

The OReilly logo is a registered trademark of OReilly Media, Inc. Using Asyncio in Python 3, the cover image, and related trade dress are trademarks of OReilly Media, Inc.

While the publisher and the author have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the author disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights.

978-1-491-99968-4

[LSI]

To my partner, Gina: I deeply appreciate all your encouragement andsupport while writing this book; it has made all the difference.

Caleb

Preface

Python 3.4 introduced the asyncio library, and Python 3.5 producedthe async and await keywords to use it palatably. These newadditions allow so-called asynchronous programming.

All of these new features, which well refer to under the single nameAsyncio, have been received by the Python community somewhat warily;there seems to be a segment of the community that views the new Asynciofeatures as very complex and difficult to understand. This view isnot limited to beginners: several high-profile contributors to thePython community have expressed doubts about the complexity of the AsyncioAPI in Python, and educators in the community have expressed concernabout how best to teach Asyncio to students.

Most people with a few years experience in Python have used threadsbefore, and even if you havent, you are still likely to haveexperienced blocking before. For example, if youve written programsusing the wonderful requests library, you will surely have noticedhow your program pauses for a bit while it does requests.get(url); thisis blocking behavior.

For one-off tasks this is fine, but if you want to fetch tenthousand URLs simultaneously, its going to be difficult to userequests; so large-scale concurrency is a big reason to learn anduse Asyncio. But the other big attraction of Asyncio over preemptivethreading is safety: it will be much easier for you to avoidrace-condition bugs with Asyncio.

My goal with this book is to help as much as I can to give you a basicunderstanding of why these new features have been introduced, how tounderstand them, and how to approach making use of these new featuresin your own projects. More specifically, Im aiming to provide:

  1. a critical comparison of asyncio and threading for concurrentnetwork programming

  2. understanding of the new async/awaitlanguage syntax

  3. a general overview of the new asynciostandard library featuresin Python

  4. detailed, extended case studies with code, showing how to use afew of the more popular Asyncio-compatible third-party libraries

Well begin with a story that illustrates the shift in thinking thatmust accompany a transition from threaded to async programming. Then,in the next part we take a look at the changes in the Python languageitself that were made to accommodate async programming. Finally, wellexplore some of the ways in which these new features can be used mosteffectively.

The new Asyncio features are not going to radically change the way youwrite programs. They provide specific tools that make sense only forspecific situations; but in the right situations, asynciois exceptionally useful. In this book were going to describe thosesituations, and how you can best approach them using the new Asynciofeatures.

Chapter 1. Introduction

My story is a lot like yours, only more interesting cause it involves robots.

Bender, Futurama episode 30% Iron Chef

The most common question I receive about Asyncio in Python 3 is this:What is it, and what do I do with it? The following story provides abackdrop for answering these questions. The central focus of Asyncio isabout how to best perform multiple concurrent tasks at the same time.And not just any sort of tasks, but specifically tasks that involvewaiting periods. The key insight required with this style ofprogramming is that while you wait for this task to complete, workon other tasks can be performed.

The Restaurant of ThreadBots

The year is 2051, and you find yourself in the restaurant business!Automation, largely by robot workers, powers most of the economy, butit turns out that humans still enjoy going out to eat once in a while.In your restaurant, all the employees are robots; humanoid, of course,but unmistakably robots. The most successful manufacturer of robots isof course Threading Inc., and robot workers from this company havecome to be called ThreadBots.

Except for this small robotic detail, your restaurant looks andoperates like one of those old-time restaurants from, say, 2018. Yourguests will be looking for that vintage experience. They want freshfood prepared from scratch. They want to sit at tables. They want towait for their mealsbut only a little. They want to pay at the end,and they sometimes even want to leave a tip, for old-times sake, ofcourse.

Naturally, being new to the robotic restaurant business, you do whatevery other restaurateur does, and you hire a small fleet of robots:one to greet new diners at the front desk (hostbot); one to waittables and take orders (waitbot); one to do the cooking (chefbot); andone to manage the bar (winebot).

Hungry diners will arrive at the front desk, and will be greeted byyour front-of-house threadbot. They are then directed to a table, andonce they are seated, your waiter threadbot will take their order.Then, the waiter threadbot will take that order to the kitchen on aslip of paper (because you want to preserve that old-time experience,remember?). The chefbot will look up the order on the slip and beginpreparing the food. The waitbot will periodically check whether thefood is ready, and if so, will immediately take the dish to thecustomers table. When the guests are ready to leave, theyreturn to greetbot who calculates the bill, and graciously wishesthem a pleasant evening further.

You soon open your restaurant, and exactly as you had anticipated,your menu is a hit and you soon grow a large customer base. Your robotemployees do exactly what theyre told, and they are perfectly good atthe tasks you assigned them. Everything is going really well, and youreally couldnt be happier.

Next page
Light

Font size:

Reset

Interval:

Bookmark:

Make

Similar books «Using Asyncio in Python 3»

Look at similar books to Using Asyncio in Python 3. We have selected literature similar in name and meaning in the hope of providing readers with more options to find new, interesting, not yet read works.


Reviews about «Using Asyncio in Python 3»

Discussion, reviews of the book Using Asyncio in Python 3 and just readers' own opinions. Leave your comments, write what you think about the work, its meaning or the main characters. Specify what exactly you liked and what you didn't like, and why you think so.