Skip to main content

Breadcrumbs Collector

  • About author
  • Cookie Policy
  • Privacy Policy

Category: asyncio

What is asyncio’s ensure_future?

October 10, 2019October 10, 2019 Sebastian Leave a comment

tl;dr ensure_future let’s us execute a coroutine in the background, without explicitly waiting for it to finish. If we need, we can wait for it later or poll for result. In other words, this is a way of executing code in asyncio without await.

Read More

asyncio – choosing the right executor

September 6, 2017September 6, 2017 Sebastian 3 Comments

During application development with asyncio you will inevitably encounter situation when there is no asyncio-compatible library to use. It may be an API client for our business partner built with excellent requests library (that naturally doesn’t work well with asyncio) or a simpler example – a Celery. Rewriting problematic dependency may be your first thought, […]

Read More

Dive into Python’s asyncio, part 5 – protocols

May 14, 2017May 14, 2017 Sebastian Leave a comment

Protocols are asyncio’s primitives supplied as convenient base classes to quickly set up clients or servers using TCP/UDP (+ subprocesses). These are especially helpful when we need to implement low level handling of protocol of some sort. I believe they are inspired by Twisted’s protcols. Simple example of TCP echo server protocol may be (taken […]

Read More

Dive into Python’s asyncio, part 4 – simple chat with Sanic

May 7, 2017May 7, 2017 Sebastian Leave a comment

Let’s roll with something practical, namely a simple chat application using Sanic framework mentioned in previous post. Sanic supports websockets out of the box thanks to the websockets library. It’s super easy to write a handler function by using decorator (#1): @app.websocket(‘/feed’) # 1 async def feed(request, ws): while True: data = await ws.recv() await […]

Read More

Dive into Python’s asyncio, part 3 – web framework

April 30, 2017April 30, 2017 Sebastian Leave a comment

Few days ago while I was reading fullstackpython.com I came across new pythonic micro web framework based on asyncio – Sanic. Coolest thing about Sanic is that it leverages asyncio providing better performance and more efficient hardware utilization. Although it’s not feature complete yet, there are people claimimg to be using it in production and […]

Read More

Dive into Python’s asyncio, part 2

April 19, 2017May 14, 2017 Sebastian Leave a comment

All examples were tested under Python 3.6. The only asyncio rule After reading part 1 you should already know, that a heart of asyncio is an event loop. There is exactly one rule – do not block the event loop! Never ever. Fortunately, it’s quite simple to avoid this. Use only co-operative libraries for blocking […]

Read More

Dive into Python’s asyncio, part 1

April 1, 2017November 15, 2017 Sebastian Leave a comment

Concurrency was not seriously taken into account in Python when it was designed. Until 3.4 version, there were two options: threading multiprocessing Although these two modules provided programmers with handy primitives and API, they both have considerable downsides. Due to GIL presence, threaded code in Python never actually run in parallel. So all attempts to […]

Read More

Top Posts

  • How to use code coverage in Python with pytest?
  • How to implement a service layer in Django + Rest Framework
  • The Clean Architecture in Python. How to write testable and flexible code
  • Where to put all your utils in Python projects?
  • What is asyncio's ensure_future?
  • Python & the Clean Architecture in 2021
  • Meet python-mockito and leave built-in mock & patch behind
  • How to mock in Python? - (almost) definitive guide
  • Stop naming your python modules "utils"
  • How to patch in Python?

Archives

RSS Feed

  • RSS - Posts

Categories

  • python 39
  • dajsiepoznac2017 22
  • software engineering 11
  • extjs-pathfinder 9
  • clean architecture 7
  • GitHub
  • LinkedIn
  • Twitter
sparkling Theme by Colorlib Powered by WordPress
This site uses cookies: Find out more.