Skip to content
This repository was archived by the owner on May 15, 2023. It is now read-only.

Latest commit

 

History

History
51 lines (31 loc) · 2.11 KB

File metadata and controls

51 lines (31 loc) · 2.11 KB

Stupig 2017-08-23

[TOC]

Vorstellrunde

  • Andreas; Python-Evangelist, @aexea
  • Rash; Node-Evangelist, @aexea
  • Michael; Golang-Evangelist, @aexea
  • horn; Raumfahrt-Evangelist, nicht aexea
  • Johanna; Sprach-Evangelistin, @aexea
  • Andreas; Perl-Evangelist, nicht aexea
  • rixx; Django-Evangelist, @aexea
  • Myriam; Nahrungs-Evangelistin, nicht aexea

asyncio

Warum async?

Normalerweise laufen Programme sequentiell von vorne nach hinten (oben nach unten, links nach rechts). Aaaber: Vielleicht ist einem das zu langsam, besonders wenn man auf I/O wartet. I/O ist nämlich fies langsam.

Klassische Lösung: Je Anfrage/Problem/etc. einen Thread oder Prozess mit eigenem Kontext, der das Problem löst, und dann wieder aufhört.

Problem: Threading ist schwer. Threading bringt Race Conditions, Semaphoren, Locks, und sehr viel Haarausfall

Die hippe neue gute Lösung: Eventloops (in Python: asyncio)

https://deadlockempire.github.io/

Was sind Eventloops?

Wir bleiben bei einem Prozess, weil Threads uns zu schwer sind, yeah! Das heißt: Ein Thread, ein Stück Memory, alles ganz normal.

Erklärungen Anhand eines Schaubilds aus https://medium.com/the-node-js-collection/what-you-should-know-to-really-understand-the-node-js-event-loop-and-its-metrics-c4907b19da4c erfolgen.

Letztlich ist so ein Eventloop nur ein Manager-Prozess (traditionell: Scheduler), bei dem sich Code als später auszuführen melden kann. Z.B:

"Ich öffne jetzt diese Datei – wenn das Betriebssystem die bereitgestellt hat, ruf bitte diese Funktion auf, ich bin jetzt fertig".

Drunter liegt eine abstrahierende Bibliothek, die das ganze (für asyncio, aber auch für nodejs) vom Betriebssystem abstrahiert, sodass das ganze schnuffige System plattformunabhängig läuft.

Asyncio konkret

Beispiele aus: https://www.blog.pythonlibrary.org/2016/07/26/python-3-an-intro-to-asyncio/

Wir nutzen Python 3.5-Syntax: async def und await – in Python 3.4 hieß das etwas anders, funktionierte aber genau gleich.

Wir gucken uns Beispiele mit Netzwerk (aiohttp) und Dateien (aiofiles) an, um das Konzept von async def, async with, und await zu erklären.