Slide 1

Slide 1 text

プロダクションでのPython 非 同期ユースケース Trio/Trio-Utilを中 心 に Junya Fukuda PyCon JP 2024

Slide 2

Slide 2 text

•book •Python࣮ફϨγϐ •ΤΩεύʔτPythonϓϩάϥϛϯάվగ4൛ •Junya Fukudaʢ@JunyaFffʣ •Photos 📷 post 👍 •Software Engineer at Groove X, inc. •࿈ࡌ: Python Monthly Topics | gihyo.jp ͖ΐ͏ͷίʔυ 🔍GitHub jrfk talk

Slide 3

Slide 3 text

Python の 非 同期を使っていますか? ✋

Slide 4

Slide 4 text

Thank You! Python の 非 同期を使っていますか? ✋

Slide 5

Slide 5 text

Web? ✋ Python の 非 同期を使っていますか? ✋

Slide 6

Slide 6 text

Web? ✋ Database? ✋ Python の 非 同期を使っていますか? ✋

Slide 7

Slide 7 text

Web? ✋ Database? ✋ API calls? ✋ Python の 非 同期を使っていますか? ✋

Slide 8

Slide 8 text

Trio? ✋ ✋ ✋

Slide 9

Slide 9 text

🤝🤝🤝🤝🤝

Slide 10

Slide 10 text

わたしたちはロボット開発で Python 非 同期を使っています

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

😊😊😊

Slide 13

Slide 13 text

プロダクションでのPython 非 同期ユースケース Trio/Trio-Utilを中 心 に

Slide 14

Slide 14 text

プロダクションでのPython 非 同期ユースケース Trio/Trio-Utilを中 心 に

Slide 15

Slide 15 text

プロダクションでのPython 非 同期ユースケース Trio/Trio-Utilを中 心 に

Slide 16

Slide 16 text

•Trio ͱ Trio-util, asyncio ͷAPIൺֱ •anyio ͦͯ͠ subinterpreter/free threading ͱasync •Python async ͱ ϩϘοτͰͷϢʔεέʔε

Slide 17

Slide 17 text

•Python async ͱ ϩϘοτͰͷϢʔεέʔε •Why Python Async •Why Trio •Trio ͱ Trio-util, asyncio ͷAPIൺֱ •anyio ͦͯ͠ subinterpreter/free threading ͱasync

Slide 18

Slide 18 text

•Python async ͱ ϩϘοτͰͷϢʔεέʔε •Why Python Async •Why Trio •Trio ͱ Trio-util, asyncio ͷAPIൺֱ •anyio ͦͯ͠ subinterpreter/free threading ͱasync

Slide 19

Slide 19 text

•Python async ͱ ϩϘοτͰͷϢʔεέʔε •Why Python Async •Why Trio •Trio ͱ Trio-util, asyncio ͷAPIൺֱ •anyio ͦͯ͠ subinterpreter/free threading ͱasync

Slide 20

Slide 20 text

•Python async ͱ ϩϘοτͰͷϢʔεέʔε •Why Python Async •Why Trio •Trio ͱ Trio-util, asyncio ͷAPIൺֱ •anyio ͦͯ͠ subinterpreter/free threading ͱasync

Slide 21

Slide 21 text

•TrioΛ༻͍ͨϓϩμΫγϣϯϢʔεέʔεͷ۩ମྫ

Slide 22

Slide 22 text

•Trioͱasyncioͷҧ͍ͱʮstructured concurrencyʯͷ֓೦ •TrioΛ༻͍ͨϓϩμΫγϣϯϢʔεέʔεͷ۩ମྫ

Slide 23

Slide 23 text

•ͨ͘͞ΜͷIOͷ͋ΔඇಉظΞϓϦέʔγϣϯͰͷώϯτ •Trioͱasyncioͷҧ͍ͱʮstructured concurrencyʯͷ֓೦ •TrioΛ༻͍ͨϓϩμΫγϣϯϢʔεέʔεͷ۩ମྫ

Slide 24

Slide 24 text

•Python async ͱ ϩϘοτͰͷϢʔεέʔε •Why Python Async •Why Trio •Trio ͱ Trio-util, asyncio ͷAPIൺֱ •anyio ͦͯ͠ subinterpreter/free threading ͱasync

Slide 25

Slide 25 text

•Python async ͱ ϩϘοτͰͷϢʔεέʔε

Slide 26

Slide 26 text

•Python async ͱ ϩϘοτͰͷϢʔεέʔε

Slide 27

Slide 27 text

ͳͥҙࢥܾఆΤϯδϯʹ Python ඇಉظΛ࠾༻ͨ͠ͷ͔ʁ

Slide 28

Slide 28 text

Why Python Async •1ͭ໨ͷཧ༝ •2ͭ໨ͷཧ༝

Slide 29

Slide 29 text

Why Python Async •Ո଒ܕϩϘοτʮLOVOTʯ

Slide 30

Slide 30 text

Why Python Async •Ո΍ΦϑΟεͳͲͰ฻Β͢ •Ո଒ܕϩϘοτʮLOVOTʯ

Slide 31

Slide 31 text

Why Python Async •ͨ͘͞Μͷηϯαʔ •Ո଒ܕϩϘοτʮLOVOTʯ •Ո΍ΦϑΟεͳͲͰ฻Β͢

Slide 32

Slide 32 text

Why Python Async •൴Β͸֎ͷ৘ใΛͨ͘͞Μಘ͍ͯΔ

Slide 33

Slide 33 text

Why Python Async •൴Β͸֎ͷ৘ใΛͨ͘͞Μಘ͍ͯΔ $16DPSFT .$6T TFOTPST

Slide 34

Slide 34 text

Why Python Async •ͨ͘͞Μͷηϯαʔ •Ո଒ܕϩϘοτʮLOVOTʯ •Ո΍ΦϑΟεͳͲͰ฻Β͢ •؀ڥΛೝࣝͨ͠ΓɺҙࢥܾఆΛ͢ΔͨΊ

Slide 35

Slide 35 text

Ұॹʹ฻Β͢LOVOT

Slide 36

Slide 36 text

೔ৗੜ׆ʹ͓͚Δେྔͷ Πϯϓοτ Ұॹʹ฻Β͢LOVOT

Slide 37

Slide 37 text

೔ৗੜ׆ʹ͓͚Δେྔͷ Πϯϓοτ Ξ΢τϓοτ Ұॹʹ฻Β͢LOVOT

Slide 38

Slide 38 text

೔ৗੜ׆ʹ͓͚Δେྔͷ Πϯϓοτ Ξ΢τϓοτ ͦΕΒΛಉ࣌ʹߦ͏ඞཁ Ұॹʹ฻Β͢LOVOT

Slide 39

Slide 39 text

Why Python Async •1ͭ໨ͷཧ༝ - ฒߦॲཧ͕ඞཁ •ͨ͘͞Μͷ I/O Λಉ࣌ʹ

Slide 40

Slide 40 text

Why Python Async •1ͭ໨ͷཧ༝ - ฒߦॲཧ͕ඞཁ •ͨ͘͞Μͷ I/O Λಉ࣌ʹ

Slide 41

Slide 41 text

Why Python Async •1ͭ໨ͷཧ༝ - ฒߦॲཧ͕ඞཁ •2ͭ໨ͷཧ༝ •ͨ͘͞Μͷ I/O Λಉ࣌ʹ

Slide 42

Slide 42 text

Why Python Async •ͨ͘͞ΜͷϚΠΫϩαʔϏε͕ಈ͍͍ͯΔ

Slide 43

Slide 43 text

Why Python Async •ϋʔυ΢ΣΞ͔Βͷ৘ใɺΫϥ΢υ࿈ܞͳͲ΋ •ͨ͘͞ΜͷϚΠΫϩαʔϏε͕ಈ͍͍ͯΔ

Slide 44

Slide 44 text

Why Python Async •ͦͯͦ͠ΕΒΛݶΒΕͨϦιʔεͰ •ϋʔυ΢ΣΞ͔Βͷ৘ใɺΫϥ΢υ࿈ܞͳͲ΋ •ͨ͘͞ΜͷϚΠΫϩαʔϏε͕ಈ͍͍ͯΔ

Slide 45

Slide 45 text

Why Python Async •ͦͯͦ͠ΕΒΛݶΒΕͨϦιʔεͰ •ϋʔυ΢ΣΞ͔Βͷ৘ใɺΫϥ΢υ࿈ܞͳͲ΋ •ͨ͘͞ΜͷϚΠΫϩαʔϏε͕ಈ͍͍ͯΔ

Slide 46

Slide 46 text

Why Python Async •1ͭ໨ͷཧ༝ - ฒߦॲཧ͕ඞཁ •2ͭ໨ͷཧ༝ •ͨ͘͞Μͷ I/O Λಉ࣌ʹ

Slide 47

Slide 47 text

Why Python Async •ͨ͘͞Μͷ I/O Λಉ࣌ʹ •1ͭ໨ͷཧ༝ - ฒߦॲཧ͕ඞཁ •2ͭ໨ͷཧ༝ •ݶΒΕͨϦιʔε

Slide 48

Slide 48 text

Why Python Async •ͨ͘͞Μͷ I/O Λಉ࣌ʹ •1ͭ໨ͷཧ༝ - ฒߦॲཧ͕ඞཁ •2ͭ໨ͷཧ༝ •ݶΒΕͨϦιʔε Python Async

Slide 49

Slide 49 text

🤔

Slide 50

Slide 50 text

なぜ asyncio でなく Trio? 🌷

Slide 51

Slide 51 text

なぜ asyncio でなく Trio? asyncio Trio

Slide 52

Slide 52 text

なぜ asyncio でなく Trio? asyncio Trio 標準ライブラリ

Slide 53

Slide 53 text

なぜ asyncio でなく Trio? asyncio Trio 標準ライブラリ サードパーティ

Slide 54

Slide 54 text

たとえば Urllib(純正シンプル) requests(使いやすい) みたいな違いはない

Slide 55

Slide 55 text

Trio? ✋ ✋ ✋

Slide 56

Slide 56 text

Trio? ✋ ✋ ✋ (🙈PyConUS2024 でもいなかった 🤫)

Slide 57

Slide 57 text

なぜ asyncio でなく Trio? 🌷

Slide 58

Slide 58 text

なぜ asyncio でなく Trio? 🌷 わざわざ選ぶ理由ないよね

Slide 59

Slide 59 text

No content

Slide 60

Slide 60 text

Why Trio? •Robust cancellation •Structured Concurrency •User-friendly API ·ͩߴϨϕϧAPIͳ͍࣌୅ 😢 •͜ΕΛܾఆͨ͠ͷ͸ 2017೥ౙ •Python3.6ͷ࣌୅

Slide 61

Slide 61 text

🤔 Structured Concurrencyとキャンセル

Slide 62

Slide 62 text

•Structured Concurrency ͬͯԿʁ •ߏ଄Խ͞Εͨฒߦੑ •Martin Sustrik ࢯ͕2016೥2݄ʹఏএͨ֓͠೦ Structured Concurrency | 250bpm.com : https://250bpm.com/blog:71/ Why Trio? - Structured Concurrencyとキャンセル

Slide 63

Slide 63 text

•ඇಉظॲཧͷ։࢝ͱऴ͕ྃ໌֬ʹ ೖΕࢠʹͳΔ͜ͱ ͳͥೖΕࢠʹʁ Why Trio? - Structured Concurrencyとキャンセル •Structured Concurrency ͬͯ֓೦

Slide 64

Slide 64 text

•՝୊͸ʮΩϟϯηϧʯ main() foo() bar() Why Trio? - Structured Concurrencyとキャンセル

Slide 65

Slide 65 text

•՝୊͸ʮΩϟϯηϧʯ main() foo() bar() 👍 Why Trio? - Structured Concurrencyとキャンセル

Slide 66

Slide 66 text

•՝୊͸ʮΩϟϯηϧʯ main() foo() bar() Why Trio? - Structured Concurrencyとキャンセル

Slide 67

Slide 67 text

•՝୊͸ʮΩϟϯηϧʯ main() foo() bar() 🤔 Why Trio? - Structured Concurrencyとキャンセル

Slide 68

Slide 68 text

•՝୊͸ʮΩϟϯηϧʯ main() foo() bar() Why Trio? - Structured Concurrencyとキャンセル 1. ଙεϨου͸ͦͷ··ॲཧ͢Δέʔε 2. Ωϟϯηϧͯ͠ཉ͍͠έʔε

Slide 69

Slide 69 text

•՝୊͸ʮΩϟϯηϧʯ main() foo() bar() Why Trio? - Structured Concurrencyとキャンセル 1. ଙεϨου͸ͦͷ··ॲཧ͢Δέʔε 2. Ωϟϯηϧͯ͠ཉ͍͠έʔε

Slide 70

Slide 70 text

•՝୊͸ʮΩϟϯηϧʯ main() foo() bar() TrioはStructured Concurrencyとキャンセルを2017時点で実現 Why Trio? - Structured Concurrencyとキャンセル

Slide 71

Slide 71 text

•Structured Concurrency Why Trio? - Structured Concurrencyとキャンセル

Slide 72

Slide 72 text

•Structured Concurrency IUUQTEFWFMPQFSBQQMFDPNWJEFPTQMBZXXED Why Trio? - Structured Concurrencyとキャンセル

Slide 73

Slide 73 text

•Structured Concurrency IUUQTPQFOKELPSHKFQT Why Trio? - Structured Concurrencyとキャンセル

Slide 74

Slide 74 text

•Structured Concurrency IUUQTLPUMJOMBOHPSHBQJLPUMJOYDPSPVUJOFTLPUMJOYDPSPVUJOFTDPSFLPUMJOYDPSPVUJOFTDPSPVUJOFTDPQF Why Trio? - Structured Concurrencyとキャンセル

Slide 75

Slide 75 text

•Structured Concurrency Why Trio? - Structured Concurrencyとキャンセル

Slide 76

Slide 76 text

•Structured Concurrency Async Rust can be a pleasure to work with (without `Send + Sync + 'static`) Why Trio? - Structured Concurrencyとキャンセル

Slide 77

Slide 77 text

ೖࣾ ͯ͠ͳ͍

Slide 78

Slide 78 text

ͭ·Γ

Slide 79

Slide 79 text

બఆʹ ؔΘ͓ͬͯΓ·ͤΜ

Slide 80

Slide 80 text

No content

Slide 81

Slide 81 text

No content

Slide 82

Slide 82 text

Why Trio? •Robust cancellation •Structured Concurrency •User-friendly API •Trioͷΰʔϧʮusability and correctnessʯ

Slide 83

Slide 83 text

ͳͥϢʔβʔϑϨϯυϦʔͳAPI͕ඞཁʁ 🤔

Slide 84

Slide 84 text

Why Trio? - User-friendly API Python Engineers

Slide 85

Slide 85 text

Python Engineers Why Trio? - User-friendly API

Slide 86

Slide 86 text

Python Engineers Why Trio? - User-friendly API

Slide 87

Slide 87 text

Python Engineers Animators Why Trio? - User-friendly API

Slide 88

Slide 88 text

Python Engineers Animators Why Trio? - User-friendly API

Slide 89

Slide 89 text

Python Engineers Animators Kawaii Behavior Why Trio? - User-friendly API

Slide 90

Slide 90 text

Kawaii Behavior Why Trio? - User-friendly API

Slide 91

Slide 91 text

Why Trio? •Robust cancellation •Structured Concurrency •User-friendly API •Trioͷΰʔϧʮusability and correctnessʯ - Ξχϝʔλʔͱͷڠۀ

Slide 92

Slide 92 text

なぜ asyncio でなく Trio? 🌷 👍

Slide 93

Slide 93 text

Trioとasyncioの交えた 比 較 🌷 👍

Slide 94

Slide 94 text

•Robust cancellation •Structured Concurrency •User-friendly API Trio asyncio 比 較 ͜ͷ3ͭͷ؍఺Ͱ APIΛݟͯΈ·͠ΐ͏

Slide 95

Slide 95 text

🔍 GitHub jrfk talk

Slide 96

Slide 96 text

🔍 GitHub jrfk talk PEP 723対応!

Slide 97

Slide 97 text

🔍 GitHub jrfk talk PEP 723対応!

Slide 98

Slide 98 text

trio asyncio ·ͱΊ࣮ͯߦ Nursery Taskgroup Nඵޙʹ λεΫऴྃ move_on_after Timeout ஋ͷมԽΛ଴ͭ trio-util.AsyncValue ʁ Trio asyncio 比 較

Slide 99

Slide 99 text

•APIͱͯ͠ෆࢥٞͳ໊લ •nursery: อҭԂ trio.nursery 1PUFOUJBM"1*DIBOHFTUPIFMQVTFSTXIPEPOUSFBMJ[FQBSFOUJOHJTBGVMMUJNFKPCu*TTVF IUUQTHJUIVCDPNQZUIPOUSJPUSJPJTTVFT 4IPVMEXFSFOBNFOVSTFSJFT IUUQTHJUIVCDPNQZUIPOUSJPUSJPJTTVFT

Slide 100

Slide 100 text

•APIͱͯ͠ෆࢥٞͳ໊લ •nursery: อҭԂ trio.nursery 1PUFOUJBM"1*DIBOHFTUPIFMQVTFSTXIPEPOUSFBMJ[FQBSFOUJOHJTBGVMMUJNFKPCu*TTVF IUUQTHJUIVCDPNQZUIPOUSJPUSJPJTTVFT 4IPVMEXFSFOBNFOVSTFSJFT IUUQTHJUIVCDPNQZUIPOUSJPUSJPJTTVFT •ίʔυΛݟͯΈ·͠ΐ͏

Slide 101

Slide 101 text

async def child(): print("👶ࢠίϧʔνϯ ͜Μʹͪ͸") await grandchild() print("👶 ͞Α͏ͳΒ") async def grandchild(): print("👶👶ଙίϧʔνϯ ͜Μʹͪ͸") await trio.sleep(0.1) print("👶👶 ͞Α͏ͳΒ")

Slide 102

Slide 102 text

async def main(): async with trio.open_nursery() as nursery: nursery.start_soon(child) nursery.start_soon(child) nursery.start_soon(child) nursery.start_soon(child) print("ดԂ")

Slide 103

Slide 103 text

async def main(): async with trio.open_nursery() as nursery: nursery.start_soon(child) nursery.start_soon(child) nursery.start_soon(child) nursery.start_soon(child) print("ดԂ")

Slide 104

Slide 104 text

async def main(): async with trio.open_nursery() as nursery: nursery.start_soon(child) nursery.start_soon(child) nursery.start_soon(child) nursery.start_soon(child) print("ดԂ")

Slide 105

Slide 105 text

async def main(): async with trio.open_nursery() as nursery: nursery.start_soon(child) nursery.start_soon(child) nursery.start_soon(child) nursery.start_soon(child) print("ดԂ")

Slide 106

Slide 106 text

$ uv run 1_trio_nursery.py … 👶ࢠίϧʔνϯ ͜Μʹͪ͸ 👶👶ଙίϧʔνϯ ͜Μʹͪ͸ … 👶👶 ͞Α͏ͳΒ 👶 ͞Α͏ͳΒ ดԂ

Slide 107

Slide 107 text

$ uv run 1_trio_nursery.py … 👶ࢠίϧʔνϯ ͜Μʹͪ͸ 👶👶ଙίϧʔνϯ ͜Μʹͪ͸ … 👶👶 ͞Α͏ͳΒ 👶 ͞Α͏ͳΒ ดԂ

Slide 108

Slide 108 text

$ uv run 1_trio_nursery.py … 👶ࢠίϧʔνϯ ͜Μʹͪ͸ 👶👶ଙίϧʔνϯ ͜Μʹͪ͸ … 👶👶 ͞Α͏ͳΒ 👶 ͞Α͏ͳΒ ดԂ

Slide 109

Slide 109 text

$ uv run 1_trio_nursery.py … 👶ࢠίϧʔνϯ ͜Μʹͪ͸ 👶👶ଙίϧʔνϯ ͜Μʹͪ͸ … 👶👶 ͞Α͏ͳΒ 👶 ͞Α͏ͳΒ ดԂ

Slide 110

Slide 110 text

async def main(): async with trio.open_nursery() as nursery: nursery.start_soon(child) nursery.start_soon(child) nursery.start_soon(child) nursery.start_soon(child) print("ดԂ")

Slide 111

Slide 111 text

async def main(): async with trio.open_nursery() as nursery: nursery.start_soon(child) nursery.start_soon(child) nursery.start_soon(child) nursery.start_soon(child) print("ดԂ") •Structured Concurrency 🎉

Slide 112

Slide 112 text

•APIͱͯ͠ෆࢥٞͳ໊લ •nursery: อҭԂ trio.nursery

Slide 113

Slide 113 text

•APIͱͯ͠ෆࢥٞͳ໊લ •nursery: อҭԂ trio.nursery 親:main

Slide 114

Slide 114 text

•APIͱͯ͠ෆࢥٞͳ໊લ •nursery: อҭԂ trio.nursery 親:main 保育園 :open_nursery

Slide 115

Slide 115 text

•APIͱͯ͠ෆࢥٞͳ໊લ •nursery: อҭԂ trio.nursery 親:main 保育園 :open_nursery 子 :

Slide 116

Slide 116 text

•APIͱͯ͠ෆࢥٞͳ໊લ •nursery: อҭԂ trio.nursery 親:main 保育園 :open_nursery 子 : 孫:

Slide 117

Slide 117 text

•APIͱͯ͠ෆࢥٞͳ໊લ •nursery: อҭԂ trio.nursery 親:main 保育園 :open_nursery 子 : 孫:

Slide 118

Slide 118 text

•APIͱͯ͠ෆࢥٞͳ໊લ •nursery: อҭԂ trio.nursery 親:main 保育園 :open_nursery 子 :

Slide 119

Slide 119 text

•APIͱͯ͠ෆࢥٞͳ໊લ •nursery: อҭԂ trio.nursery 親:main 保育園 :open_nursery

Slide 120

Slide 120 text

•APIͱͯ͠ෆࢥٞͳ໊લ •nursery: อҭԂ trio.nursery 親:main

Slide 121

Slide 121 text

•APIͱͯ͠ෆࢥٞͳ໊લ •nursery: อҭԂ trio.nursery 親:main ࣮ࡍʹtrio discussionͷͳ͔Ͱ ʮશͯͷࢠλεΫ͕ແࣄʹऴྃ͢Δ·ͰݟकΔʯ

Slide 122

Slide 122 text

•APIͱͯ͠ෆࢥٞͳ໊લ •nursery: อҭԂ trio.nursery 親:main ࣮ࡍʹtrio discussionͷͳ͔Ͱ ʮશͯͷࢠλεΫ͕ແࣄʹऴྃ͢Δ·ͰݟकΔʯ •ଓ͍ͯΩϟϯηϧʹ͍ͭͯɺΈͯΈ·͠ΐ͏

Slide 123

Slide 123 text

async def main(): try: async with trio.open_nursery() as nursery: nursery.start_soon(coro_success) nursery.start_soon(coro_value_err) nursery.start_soon(coro_type_err) nursery.start_soon(triplet_nap) # ৸ͯΔ except* Exception as err: print(f"{err.exceptions=}") await trio.sleep(5) # 👶👶👶͕print͞Εͳ͍ print("ดԂ")

Slide 124

Slide 124 text

async def main(): try: async with trio.open_nursery() as nursery: nursery.start_soon(coro_success) nursery.start_soon(coro_value_err) nursery.start_soon(coro_type_err) nursery.start_soon(triplet_nap) # ৸ͯΔ except* Exception as err: print(f"{err.exceptions=}") await trio.sleep(5) # 👶👶👶͕print͞Εͳ͍ print("ดԂ")

Slide 125

Slide 125 text

async def main(): try: async with trio.open_nursery() as nursery: nursery.start_soon(coro_success) nursery.start_soon(coro_value_err) nursery.start_soon(coro_type_err) nursery.start_soon(triplet_nap) # ৸ͯΔ except* Exception as err: print(f"{err.exceptions=}") await trio.sleep(5) # 👶👶👶͕print͞Εͳ͍ print("ดԂ")

Slide 126

Slide 126 text

async def main(): try: async with trio.open_nursery() as nursery: nursery.start_soon(coro_success) nursery.start_soon(coro_value_err) nursery.start_soon(coro_type_err) nursery.start_soon(triplet_nap) # ৸ͯΔ except* Exception as err: print(f"{err.exceptions=}") await trio.sleep(5) # 👶👶👶͕print͞Εͳ͍ print("ดԂ")

Slide 127

Slide 127 text

async def triplet_nap(): print("௕͍ίϧʔνϯ ։࢝") await trio.sleep(3) print("👶👶👶") return "ดԂ͔ͩΒؼΓ·͠ΐ͏"

Slide 128

Slide 128 text

async def triplet_nap(): print("௕͍ίϧʔνϯ ։࢝") await trio.sleep(3) print("👶👶👶") return "ดԂ͔ͩΒؼΓ·͠ΐ͏"

Slide 129

Slide 129 text

async def triplet_nap(): print("௕͍ίϧʔνϯ ։࢝") await trio.sleep(3) print("👶👶👶") return "ดԂ͔ͩΒؼΓ·͠ΐ͏"

Slide 130

Slide 130 text

•՝୊͸ʮΩϟϯηϧʯ main() foo() bar() Why Trio? - Structured Concurrencyとキャンセル

Slide 131

Slide 131 text

$ uv run 2_trio_nursery_exceptiongroup.py ௕͍ίϧʔνϯ ։࢝ err.exceptions=(ValueError(), TypeError()) ดԂ

Slide 132

Slide 132 text

$ uv run 2_trio_nursery_exceptiongroup.py ௕͍ίϧʔνϯ ։࢝ err.exceptions=(ValueError(), TypeError()) ดԂ 👶👶👶ͳ͍

Slide 133

Slide 133 text

•APIͱͯ͠ෆࢥٞͳ໊લ •nursery: อҭԂ trio.nursery 親:main

Slide 134

Slide 134 text

•APIͱͯ͠ෆࢥٞͳ໊લ •nursery: อҭԂ trio.nursery 親:main 保育園 :open_nursery

Slide 135

Slide 135 text

•APIͱͯ͠ෆࢥٞͳ໊લ •nursery: อҭԂ trio.nursery 親:main 保育園 :open_nursery 子 :

Slide 136

Slide 136 text

•APIͱͯ͠ෆࢥٞͳ໊લ •nursery: อҭԂ trio.nursery 親:main 保育園 :open_nursery 子 :

Slide 137

Slide 137 text

•APIͱͯ͠ෆࢥٞͳ໊લ •nursery: อҭԂ trio.nursery 親:main 保育園 :open_nursery 子 : •Structured Concurrency •Ωϟϯηϧ

Slide 138

Slide 138 text

trio asyncio ·ͱΊ࣮ͯߦ Nursery Taskgroup Nඵޙʹ λεΫऴྃ move_on_after Timeout ஋ͷมԽΛ଴ͭ trio-util.AsyncValue ʁ Trio asyncio 比 較

Slide 139

Slide 139 text

•3.11Ͱ௥Ճ͞ΕͨAPI asyncio.Taskgroup

Slide 140

Slide 140 text

•3.11Ͱ௥Ճ͞ΕͨAPI asyncio.Taskgroup

Slide 141

Slide 141 text

•3.11Ͱ௥Ճ͞ΕͨAPI asyncio.Taskgroup

Slide 142

Slide 142 text

•3.11Ͱ௥Ճ͞ΕͨAPI asyncio.Taskgroup

Slide 143

Slide 143 text

async def child(): print("👶ࢠίϧʔνϯ ͜Μʹͪ͸") await grandchild() print("👶 ͞Α͏ͳΒ") async def grandchild(): print("👶👶ଙίϧʔνϯ ͜Μʹͪ͸") await trio.sleep(0.1) print("👶👶 ͞Α͏ͳΒ")

Slide 144

Slide 144 text

async def main(): async with asyncio.TaskGroup() as g: g.create_task(child()) g.create_task(child()) g.create_task(child()) g.create_task(child(), name="Α͘৸ͯΔ") print("ดԂ")

Slide 145

Slide 145 text

async def main(): async with asyncio.TaskGroup() as g: g.create_task(child()) g.create_task(child()) g.create_task(child()) g.create_task(child(), name="Α͘৸ͯΔ") print("ดԂ")

Slide 146

Slide 146 text

$ uv run 1_asyncio_taskgroup.py … 👶ࢠίϧʔνϯ ͜Μʹͪ͸ 👶👶ଙίϧʔνϯ ͜Μʹͪ͸ … 👶👶 ͞Α͏ͳΒ 👶 ͞Α͏ͳΒ ดԂ

Slide 147

Slide 147 text

async def main(): async with asyncio.TaskGroup() as g: g.create_task(child()) g.create_task(child()) g.create_task(child()) g.create_task(child(), name="Α͘৸ͯΔ") print("ดԂ")

Slide 148

Slide 148 text

async def main(): async with asyncio.TaskGroup() as g: g.create_task(child()) g.create_task(child()) g.create_task(child()) g.create_task(child(), name="Α͘৸ͯΔ") print("ดԂ") •Structured Concurrency 🎉

Slide 149

Slide 149 text

async def main(): async with asyncio.TaskGroup() as g: g.create_task(child()) g.create_task(child()) g.create_task(child()) g.create_task(child(), name="Α͘৸ͯΔ") print("ดԂ") •Structured Concurrency 🎉 •Ωϟϯηϧ΋ΈͯΈ·͠ΐ͏

Slide 150

Slide 150 text

async def main(): try: async with asyncio.TaskGroup() as g: task1 = g.create_task(coro_success()) task2 = g.create_task(coro_value_err()) task3 = g.create_task(coro_type_err()) task4 = g.create_task(triplet_nap(), name="Α͘৸ͯΔ") results = [task1.result(), task2.result(), task3.result()] print(f"{results=}") except* Exception as err: print(f"{err.exceptions=}") await asyncio.sleep(5) # 👶👶👶͕print͞Εͳ͍͜ͱΛ֬ೝ print("ดԂ")

Slide 151

Slide 151 text

async def main(): try: async with asyncio.TaskGroup() as g: task1 = g.create_task(coro_success()) task2 = g.create_task(coro_value_err()) task3 = g.create_task(coro_type_err()) task4 = g.create_task(triplet_nap(), name="Α͘৸ͯΔ") results = [task1.result(), task2.result(), task3.result()] print(f"{results=}") except* Exception as err: print(f"{err.exceptions=}") await asyncio.sleep(5) # 👶👶👶͕print͞Εͳ͍͜ͱΛ֬ೝ print("ดԂ")

Slide 152

Slide 152 text

$ uv run 2_asyncio_taskgroup_exceptiongroup.py ௕͍ίϧʔνϯ ։࢝ err.exceptions=(ValueError(), TypeError()) ดԂ

Slide 153

Slide 153 text

$ uv run 2_asyncio_taskgroup_exceptiongroup.py ௕͍ίϧʔνϯ ։࢝ err.exceptions=(ValueError(), TypeError()) ดԂ 👶👶👶ͳ͍

Slide 154

Slide 154 text

Trio asyncio 交 比 較 trio asyncio ಛ௃ ·ͱΊ࣮ͯߦ Nursery Taskgroup Nඵޙʹ λεΫऴྃ move_on_after Timeout ஋ͷมԽΛ଴ͭ trio-util.AsyncValue ʁ

Slide 155

Slide 155 text

Trio asyncio 交 比 較 trio asyncio ಛ௃ ·ͱΊ࣮ͯߦ Nursery Taskgroup ߏ଄Խ 🙆 Ωϟϯηϧ 🙆 ϑϨϯυϦ 🙆 Nඵޙʹ λεΫऴྃ move_on_after Timeout ஋ͷมԽΛ଴ͭ trio-util.AsyncValue ʁ

Slide 156

Slide 156 text

Trio asyncio 交 比 較 trio asyncio ಛ௃ ·ͱΊ࣮ͯߦ Nursery Taskgroup ߏ଄Խ 🙆 Ωϟϯηϧ 🙆 ϑϨϯυϦ 🙆 Nඵޙʹ λεΫऴྃ move_on_after Timeout ஋ͷมԽΛ଴ͭ trio-util.AsyncValue ʁ

Slide 157

Slide 157 text

async def main(): with trio.move_on_after(1) as cancel_scope: await triplet_nap() if cancel_scope.cancelled_caught: print("ͪΌΜͱ͓͖ͯͶ") print("͓ΘΓ")

Slide 158

Slide 158 text

async def main(): with trio.move_on_after(1) as cancel_scope: await triplet_nap() if cancel_scope.cancelled_caught: print("ͪΌΜͱ͓͖ͯͶ") print("͓ΘΓ") 時間 設定

Slide 159

Slide 159 text

async def main(): with trio.move_on_after(1) as cancel_scope: await triplet_nap() if cancel_scope.cancelled_caught: print("ͪΌΜͱ͓͖ͯͶ") print("͓ΘΓ")

Slide 160

Slide 160 text

async def main(): with trio.move_on_after(1) as cancel_scope: await triplet_nap() if cancel_scope.cancelled_caught: print("ͪΌΜͱ͓͖ͯͶ") print("͓ΘΓ")

Slide 161

Slide 161 text

async def main(): with trio.move_on_after(1) as cancel_scope: await triplet_nap() if cancel_scope.cancelled_caught: print("ͪΌΜͱ͓͖ͯͶ") print("͓ΘΓ") •Structured Concurrency 🎉

Slide 162

Slide 162 text

async def triplet_nap(): print("௕͍ίϧʔνϯ ։࢝") await trio.sleep(3) print("👶👶👶") return "ดԂ͔ͩΒؼΓ·͠ΐ͏"

Slide 163

Slide 163 text

async def triplet_nap(): print("௕͍ίϧʔνϯ ։࢝") await trio.sleep(3) print("👶👶👶") return "ดԂ͔ͩΒؼΓ·͠ΐ͏"

Slide 164

Slide 164 text

$ uv run 3_trio_move_on_after_except.py … ௕͍ίϧʔνϯ ։࢝ ͪΌΜͱ͓͖ͯͶ ͓ΘΓ 👶👶👶ͳ͍

Slide 165

Slide 165 text

Trio asyncio 交 比 較 trio asyncio ಛ௃ ·ͱΊ࣮ͯߦ Nursery Taskgroup ߏ଄Խ 🙆 Ωϟϯηϧ 🙆 ϑϨϯυϦ 🙆 Nඵޙʹ λεΫऴྃ move_on_after Timeout ஋ͷมԽΛ଴ͭ trio-util.AsyncValue ʁ

Slide 166

Slide 166 text

async def main(): try: async with asyncio.timeout(1): await triplet_nap() except TimeoutError as err: print(f"{err=}") print("ͪΌΜͱ͓͖ͯͶ") print("͓ΘΓ")

Slide 167

Slide 167 text

async def main(): try: async with asyncio.timeout(1): await triplet_nap() except TimeoutError as err: print(f"{err=}") print("ͪΌΜͱ͓͖ͯͶ") print("͓ΘΓ") 時間 設定

Slide 168

Slide 168 text

async def main(): try: async with asyncio.timeout(1): await triplet_nap() except TimeoutError as err: print(f"{err=}") print("ͪΌΜͱ͓͖ͯͶ") print("͓ΘΓ") 時間 設定 •Structured Concurrency 🎉

Slide 169

Slide 169 text

async def triplet_nap(): print("௕͍ίϧʔνϯ ։࢝") await asyncio.sleep(3) print("👶👶👶") return "ดԂ͔ͩΒؼΓ·͠ΐ͏"

Slide 170

Slide 170 text

async def triplet_nap(): print("௕͍ίϧʔνϯ ։࢝") await trio.sleep(3) print("👶👶👶") return "ดԂ͔ͩΒؼΓ·͠ΐ͏"

Slide 171

Slide 171 text

$ uv run 3_asyncio_timeout.py … ௕͍ίϧʔνϯ ։࢝ err=TimeoutError() ͪΌΜͱ͓͖ͯͶ ͓ΘΓ

Slide 172

Slide 172 text

$ uv run 3_asyncio_timeout.py … ௕͍ίϧʔνϯ ։࢝ err=TimeoutError() ͪΌΜͱ͓͖ͯͶ ͓ΘΓ 👶👶👶ͳ͍

Slide 173

Slide 173 text

Trio asyncio 交 比 較 trio asyncio ಛ௃ ·ͱΊ࣮ͯߦ Nursery Taskgroup ߏ଄Խ 🙆 Ωϟϯηϧ 🙆 ϑϨϯυϦ 🙆 Nඵޙʹ λεΫऴྃ move_on_after Timeout ஋ͷมԽΛ଴ͭ trio-util.AsyncValue ʁ

Slide 174

Slide 174 text

Trio asyncio 交 比 較 trio asyncio ಛ௃ ·ͱΊ࣮ͯߦ Nursery Taskgroup ߏ଄Խ 🙆 Ωϟϯηϧ 🙆 ϑϨϯυϦ 🙆 Nඵޙʹ λεΫऴྃ move_on_after Timeout ߏ଄Խ 🙆 Ωϟϯηϧ 🙆 ϑϨϯυϦ 🙆 ஋ͷมԽΛ଴ͭ trio-util.AsyncValue ʁ

Slide 175

Slide 175 text

🤔

Slide 176

Slide 176 text

🤔

Slide 177

Slide 177 text

Trio asyncio 交 比 較 Python >= 3.11 trio asyncio ಛ௃ ·ͱΊ࣮ͯߦ Nursery Taskgroup ߏ଄Խ 🙆 Ωϟϯηϧ 🙆 ϑϨϯυϦ 🙆 Nඵޙʹ λεΫऴྃ move_on_after Timeout ߏ଄Խ 🙆 Ωϟϯηϧ 🙆 ϑϨϯυϦ 🙆 ஋ͷมԽΛ଴ͭ trio-util.AsyncValue ʁ

Slide 178

Slide 178 text

Trio asyncio 交 比 較 Python < 3.11 trio asyncio asyncioͷಛ௃ ·ͱΊ࣮ͯߦ Nursery gather ߏ଄Խ 🙅 Ωϟϯηϧ 🤔 ϑϨϯυϦ 🤔 Nඵޙʹ λεΫऴྃ move_on_after wait_for ߏ଄Խ 🙅 Ωϟϯηϧ 🤔 ϑϨϯυϦ 🤔 ஋ͷมԽΛ଴ͭ trio-util.AsyncValue ʁ 今 使 ! !

Slide 179

Slide 179 text

🤔 🌷 👍

Slide 180

Slide 180 text

🤔 🌷 👍

Slide 181

Slide 181 text

🤔 🌷 👍

Slide 182

Slide 182 text

🤔 🌷 👍

Slide 183

Slide 183 text

Trio asyncio 交 比 較 Python >= 3.11 trio asyncio ಛ௃ ·ͱΊ࣮ͯߦ Nursery Taskgroup ߏ଄Խ 🙆 Ωϟϯηϧ 🙆 ϑϨϯυϦ 🙆 Nඵޙʹ λεΫऴྃ move_on_after Timeout ߏ଄Խ 🙆 Ωϟϯηϧ 🙆 ϑϨϯυϦ 🙆 ஋ͷมԽΛ଴ͭ trio-util.AsyncValue ʁ

Slide 184

Slide 184 text

Trio asyncio 交 比 較 Python >= 3.11 trio asyncio ಛ௃ ·ͱΊ࣮ͯߦ Nursery Taskgroup ߏ଄Խ 🙆 Ωϟϯηϧ 🙆 ϑϨϯυϦ 🙆 Nඵޙʹ λεΫऴྃ move_on_after Timeout ߏ଄Խ 🙆 Ωϟϯηϧ 🙆 ϑϨϯυϦ 🙆 ஋ͷมԽΛ଴ͭ trio-util.AsyncValue ʁ

Slide 185

Slide 185 text

大 量の 入力 に対して状態管理をする AsyncValue

Slide 186

Slide 186 text

大 量の 入力 に対して状態管理をする AsyncValue trio_util.AsyncValue

Slide 187

Slide 187 text

Handling Multiple Inputs •Event-Driven ͳΞϓϩʔνͷAPI܈ ΑΓϑϨϯυϦʔͳ֦ு •Trio-util 🔍HJUIVCUSJPVUJM IUUQTHJUIVCDPN HSPPWFYUSJPVUJM

Slide 188

Slide 188 text

Handling Multiple Inputs •AsyncValue Class 👀

Slide 189

Slide 189 text

Handling Multiple Inputs •AsyncValue Class 👀 •஋΍awaitable ΛҾ਺ʹ •val = AyncValue(2024) Έ͍ͨͳײ͡

Slide 190

Slide 190 text

Handling Multiple Inputs •AsyncValue Class 👀 •஋΍awaitable ΛҾ਺ʹ •val = AyncValue(2024) Έ͍ͨͳײ͡ •ͦΕΛ·ͱΊΔ compose_event ΋͋Γ·͢

Slide 191

Slide 191 text

Handling Multiple Inputs •AsyncValue Class 👀 •஋΍awaitable ΛҾ਺ʹ •val = AyncValue(2024) Έ͍ͨͳײ͡ •ओͳAPI͸3ͭ঺հ

Slide 192

Slide 192 text

Handling Multiple Inputs •AsyncValue Class 👀 •஋΍awaitable ΛҾ਺ʹ •val.wait_value(஋ or ؔ਺) •Ҿ਺͕஋ͷ৔߹ɺvalue͕Ҿ਺ͷ஋ʹͳΔ·Ͱ଴ͭ

Slide 193

Slide 193 text

Handling Multiple Inputs •AsyncValue Class 👀 •஋΍awaitable ΛҾ਺ʹ •val.wait_value(஋ or ؔ਺) •val.wait_transition(ۭ or ஋ or ؔ਺) •஋ͷભҠɾมԽɾؔ਺ͷঢ়ଶΛ଴ͭ

Slide 194

Slide 194 text

Handling Multiple Inputs •AsyncValue Class 👀 •஋΍awaitable ΛҾ਺ʹ •val.wait_value(஋ or ؔ਺) •val.wait_transition(ۭ or ஋ or ؔ਺) •Val.eventual_value(ۭ or ஋ or ؔ਺) •৚݅Λຬͨͨ͠ΒloopΛճ͢

Slide 195

Slide 195 text

Handling Multiple Inputs •AsyncValue Class 👀 •஋΍awaitable ΛҾ਺ʹ •val.wait_value(஋ or ؔ਺) •val.wait_transition(ۭ or ஋ or ؔ਺) •eventual_value(ۭ or ஋ or ؔ਺) •࣮ࡍʹͲ͏ಈ͔͘ΈͯΈ·͠ΐ͏

Slide 196

Slide 196 text

Handling Multiple Inputs •४උ 👀

Slide 197

Slide 197 text

Handling Multiple Inputs •४උ 👀 •ϥϯμϜͳ਺ࣈΛฦ͢WebSocketαʔό VWSVO@TJNQMF@XFCTPDLFU@TFSWFSQZ

Slide 198

Slide 198 text

Handling Multiple Inputs •४උ 👀 •ϥϯμϜͳ਺ࣈΛฦ͢WebSocketαʔό VWSVO@TJNQMF@XFCTPDLFU@TFSWFSQZ •AsyncValueΛcompose_eventͰ·ͱΊɺͦΕΛ؂ࢹ͢Δ

Slide 199

Slide 199 text

Handling Multiple Inputs •४උ 👀 •ϥϯμϜͳ਺ࣈΛฦ͢WebSocketαʔό VWSVO@TJNQMF@XFCTPDLFU@TFSWFSQZ •👶 ͕ ஋͕มԽ͢Δͨͼʹɺग़ྗ͠·͢ •AsyncValueΛcompose_eventͰ·ͱΊɺͦΕΛ؂ࢹ͢Δ

Slide 200

Slide 200 text

async def main(): async with trio.open_nursery() as nursery: ws = await connect_websocket( nursery=nursery, host="localhost", port=8888, resource="/", ) event1 = AsyncValue("👶") event2 = AsyncValue("🍼") nursery.start_soon(fetch, ws, event1, event2) with compose_values(event1=event1, event2=event2) as composite_eve async for v in composite_event.eventual_values(): print(f"{v=}") •Continuously watch for value changes 👀

Slide 201

Slide 201 text

async def main(): async with trio.open_nursery() as nursery: ws = await connect_websocket( nursery=nursery, host="localhost", port=8888, resource="/", ) event1 = AsyncValue("👶") event2 = AsyncValue("🍼") nursery.start_soon(fetch, ws, event1, event2) with compose_values(event1=event1, event2=event2) as composite_eve async for v in composite_event.eventual_values(): print(f"{v=}") •Continuously watch for value changes 👀

Slide 202

Slide 202 text

async def main(): async with trio.open_nursery() as nursery: ws = await connect_websocket( nursery=nursery, host="localhost", port=8888, resource="/", ) event1 = AsyncValue("👶") event2 = AsyncValue("🍼") nursery.start_soon(fetch, ws, event1, event2) with compose_values(event1=event1, event2=event2) as composite_eve async for v in composite_event.eventual_values(): print(f"{v=}") •Continuously watch for value changes 👀

Slide 203

Slide 203 text

async def main(): async with trio.open_nursery() as nursery: ws = await connect_websocket( nursery=nursery, host="localhost", port=8888, resource="/", ) event1 = AsyncValue("👶") event2 = AsyncValue("🍼") nursery.start_soon(fetch, ws, event1, event2) with compose_values(event1=event1, event2=event2) as composite_eve async for v in composite_event.eventual_values(): print(f"{v=}") •Continuously watch for value changes 👀

Slide 204

Slide 204 text

async def main(): async with trio.open_nursery() as nursery: ws = await connect_websocket( nursery=nursery, host="localhost", port=8888, resource="/", ) event1 = AsyncValue("👶") event2 = AsyncValue("🍼") nursery.start_soon(fetch, ws, event1, event2) with compose_values(event1=event1, event2=event2) as composite_eve async for v in composite_event.eventual_values(): print(f"{v=}") •Continuously watch for value changes 👀

Slide 205

Slide 205 text

async def main(): async with trio.open_nursery() as nursery: ws = await connect_websocket( nursery=nursery, host="localhost", port=8888, resource="/", ) event1 = AsyncValue("👶") event2 = AsyncValue("🍼") nursery.start_soon(fetch, ws, event1, event2) with compose_values(event1=event1, event2=event2) as composite_eve async for v in composite_event.eventual_values(): print(f"{v=}") •Continuously watch for value changes 👀

Slide 206

Slide 206 text

async def main(): async with trio.open_nursery() as nursery: ws = await connect_websocket( nursery=nursery, host="localhost", port=8888, resource="/", ) event1 = AsyncValue("👶") event2 = AsyncValue("🍼") nursery.start_soon(fetch, ws, event1, event2) with compose_values(event1=event1, event2=event2) as composite_eve async for v in composite_event.eventual_values(): print(f"{v=}") •Continuously watch for value changes 👀

Slide 207

Slide 207 text

•Continuously watch for value changes 👀

Slide 208

Slide 208 text

大 量の 入力 に対して状態管理をする AsyncValue trio_util.AsyncValue

Slide 209

Slide 209 text

Handling Multiple Inputs •Trio-util does not support anyio yet •There is no API that performs the same function. •asyncio-util IUUQTHJUIVCDPNKSGLBTZODJPVUJM Here is today's code

Slide 210

Slide 210 text

•Python async ͱ ϩϘοτͰͷϢʔεέʔε •Why Python Async •Why Trio •Trio ͱ Trio-util, asyncio ͷAPIൺֱ •anyio ͦͯ͠ subinterpreter/free threading ͱasync

Slide 211

Slide 211 text

anyio •asyncio ͱ trio Λܨ͙Χέϋγ •2018 2018೥10݄ Alex Grönholm ࢯ •࡞੒ͨ͠ओͳཧ༝ •Pythonͷඇಉظϓϩάϥϛϯάʹ͓͚Δॊೈੑͱ ߴϨϕϧͷந৅ԽΛఏڙ •ΑΓ࢖͍΍͘͢ɺΑΓҰ؏ੑͷ͋Δ ඇಉظϓϩάϥϛϯάͷܦݧΛఏڙ͔ͨͬͨ͠ #385: Higher level Python asyncio with AnyIO Transcript

Slide 212

Slide 212 text

anyio •asyncio ͱ trio Λܨ͙Χέϋγ #385: Higher level Python asyncio with AnyIO Transcript •Global backend ͱ͍͏ߟ͑ํ •ଟ͘ͷඇಉظϥΠϒϥϦͰ࠾༻, FastAPI, HTTPX…

Slide 213

Slide 213 text

if __name__ == "__main__": anyio.run(main, backend="asyncio") # ͜ΕΛtrioʹม͑Δ͚ͩͰಈ͘

Slide 214

Slide 214 text

if __name__ == "__main__": anyio.run(main, backend="asyncio") # ͜ΕΛtrioʹม͑Δ͚ͩͰಈ͘ uv run 5_anyio_sample.py

Slide 215

Slide 215 text

subinterpreter/free threading •subinterpreter/free threading

Slide 216

Slide 216 text

subinterpreter/free threading •subinterpreter/free threading

Slide 217

Slide 217 text

# αϒΠϯλϓϦλͰ࣮ߦ͢Δؔ਺ def run_sub_interpreter(): interp_id = interpreters.create() interpreters.run_string( interp_id, """ import asyncio async def async_task(): for i in range(5): ...

Slide 218

Slide 218 text

# αϒΠϯλϓϦλͰ࣮ߦ͢Δؔ਺ def run_sub_interpreter(): interp_id = interpreters.create() interpreters.run_string( interp_id, """ import asyncio async def async_task(): for i in range(5): ... uv run 6_subinterpreters_asyncio.py

Slide 219

Slide 219 text

•ΑΓշదͳඇಉظϥΠϑΛ •ͨ͘͞ΜͷIOͷ͋ΔඇಉظΞϓϦέʔγϣϯͰͷώϯτ •Trioͱasyncioͷҧ͍ͱʮstructured concurrencyʯͷ֓೦ •TrioΛ༻͍ͨϓϩμΫγϣϯϢʔεέʔεͷ۩ମྫ

Slide 220

Slide 220 text

reference •Simplifying Python's Async with Trio •https://talkpython.fm/episodes/show/167/simplifying-pythons-async-with-trio •Higher level Python asyncio with AnyIO •https://talkpython.fm/episodes/show/385/higher-level-python-asyncio-with-anyio •groove-x / trio-util •https://github.com/groove-x/trio-util •Structured Concurrency - Martin Sústrik •https://250bpm.com/blog:71/

Slide 221

Slide 221 text

ご静聴ありがとうございました 👋