Mohamed Mustapha Tahrioui
Darmstadt, Hessen, Germany
Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub via the books product page, located at www.apress.com/978-1-4842-4400-5 . For more detailed information, please visit http://www.apress.com/source-code .
ISBN 978-1-4842-4400-5 e-ISBN 978-1-4842-4401-2
https://doi.org/10.1007/978-1-4842-4401-2
Mohamed Mustapha Tahrioui 2019
This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein.
Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-sbm.com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.
Introduction
Motivation
The Python programming language adopted a preemptive concurrency framework in the early 90s via the threading module, which strived to mimic the Java concurrency library, as per the respective commit message.
A simple but powerful mechanism governs concurrent execution of bytecode in most Python implementations. This mechanism is called the GIL (global interpreter lock). The interpreter consumes one bytecode instruction at a time.
This effectively means that only one thread can run at the same time (in one interpreter process). Despite this fact, the underlying native thread implementation might be able to run more than one thread at a time.
The threads are appointed fair amounts of CPU time. Without employing sophisticated introspection techniques, this boils down to simple/naive time-based scheduling algorithms.
Taking this approach in the past would often yield inferior solutions to an equivalent single threaded program, for Python implementation with a GIL like CPython.
Since removing the GIL is not an option, failed because they degraded the single threading performance significantly, the concurrency situation meant having only the threading module.
What Is Asyncio?
The cooperative concurrency framework asyncio was written to address the need for fast single-threaded programs that don't waste CPU time on I/O bound tasks.
Its primitives like coroutines and event loops allow developers to execute code only when its not waiting for I/O and to yield control back for other tasks.
Conclusion
Since its advent, asyncio has added countless APIs and keywords to the Python language ( async / await ). Its steep learning curve scares some developers from trying it. However, its a powerful technology thats even been used by big players like Instagram .
The motivation of this book is to help more developers adopt asyncio and experience the joy of using asyncio for fun and profit. With that said, enjoy this book while learning more about asyncio!
Acknowledgments
I would like to express my deep gratitude to
Mrs. Aditee Mirashi
Mr. Todd Green
Mr. Celestin Suresh John
Mr. James Markham
Mr. Matthew Moodle
Mr. Said El Mallouki
for their invaluable efforts during the execution of my book.
Furthermore, my special thanks are extended to my company axxessio and in special to
Mr. Goodarz Mahboobi
Mr. Keyvan Mahbobi
Table of Contents
About the Author and About the Technical Reviewer
About the Author
Mohamed Mustapha Tahrioui
has been a programmer for seven years and currently serves as a senior software engineer at axxessio. He is on the core team of the asyncio-heavy Telekom Smarthub project, where he offers his expertise for implementation, backward compatible architecture and implementation. He also offers full stack development via his IT consultancy Pi Intelligence, using Python, Java, JavaScript, Docker, PostgreSQL, MongoDB, and more.
About the Technical Reviewer
Said El Mallouki
is a textbook computer geek with decades of experience designing and developing enterprise IT systems. His early encounters with the internals of computers took place at IBMs production facility in Germany more than two decades ago. In his current occupation as a technology lead, he is developing a toolchain for a natural language-understanding system at Deutsche Telekom. The intricacies of complex distributed systems were always on the top of his interest list. With three degrees in IT, business, and marketing, he combines a solid theoretical foundation with plenty of real-life experience. Living in Germany by the Rhine with his wife Andrea and their 18-month son Felix, his current favorite leisure activity is to be a devoted father.
Footnotes
https://docs.python.org/3/faq/library.html#can-t-we-get-rid-of-the-global-interpreter-lock
https://code.google.com/archive/p/python-safethread
https://www.youtube.com/watch?v=ACgMTqX5Ee4
Mohamed Mustapha Tahrioui 2019
Mohamed Mustapha Tahrioui asyncio Recipes https://doi.org/10.1007/978-1-4842-4401-2_1
1. Preparing for the Recipes
Mohamed Mustapha Tahrioui
(1)
Darmstadt, Hessen, Germany