Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
asyncioを軽くさわってみた
Search
Satoshi Miura
September 15, 2015
Technology
180
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
asyncioを軽くさわってみた
第28回Python東海の発表資料
Satoshi Miura
September 15, 2015
More Decks by Satoshi Miura
See All by Satoshi Miura
MarkdownでもSphinx
mursts
1
470
お金ダッシュボードを作ってみた
mursts
0
350
FlaskとYomanでHello World
mursts
0
400
Google App Engine入門
mursts
0
670
Other Decks in Technology
See All in Technology
Multica × 長期記憶:40個のミニプロジェクト管理
eiei114
1
230
GoCon2026 - Open Source, Open World
sanposhiho
2
2.2k
AIで実装は速くなった。なのにプロダクトは速くならない。職能の壁を越えて価値のフローを設計する
nwiizo
7
7.7k
Podは生きているのにGoだけが落ちる:GOGCとGOMEMLIMITで追うInvisible OOM Killの謎
tkc66buzz
1
500
株式会社シーエーシー エンジニア向け会社紹介資料
cac
0
57k
When Does a Local Qwen Start to Break
morshoto
0
200
2026-09-04 SRE Tech Talk #15 怠惰なTerraform / Lazy Terraform
masasuzu
0
230
2026-09-11 【Snowflake World Tour Tokyo 2026】Snowflakeを起点に、AI Agentが自律稼働し続ける未来へ / Driving AI Agents with Snowflake
civitaspo
0
270
Adaptive Warehouse を今すぐ導入すべき理由と迷ったときの判断基準
__allllllllez__
0
150
2026-09-09 【sigma_ucj#1】Sigma を IaC 管理したい! / IaC for Sigma
civitaspo
0
110
生成AIのテナント制御とシャドーMCP対策 | AIを"止めずに"、情報を守る
yukun
0
140
あるけみー式LTスライド作成術
alchemy1115
1
160
Featured
See All Featured
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.6k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6.1k
Leo the Paperboy
mayatellez
8
2.3k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
500
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.3k
Bash Introduction
62gerente
615
220k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.6k
Between Models and Reality
mayunak
4
450
Side Projects
sachag
455
43k
Unsuck your backbone
ammeep
672
58k
First, design no harm
axbom
PRO
2
1.3k
Transcript
asyncioΛઙ͘͞Θͬͯ Έͨ 2015.09.12 Python౦ւ 28th
͓લͩΕΑ • Έ͏Β͞ͱ͠(@mursts) • Python౦ւͷཧਓͷҰਓͰ͢ • ࠷ۙGoΛ৮Γ࢝Ί·ͨ͠ • Tour of
Go ͚ͩ
࠷ॳʹͪΐͬͱ͚ͩGoͷ
GoͷΑ͍ͱ͜
Gopher͕͔Θ͍͍ ※ݸਓతͳײͰ͢
The Go gopher was designed by Renee French. The gopher
vector data was made by Takuya Ueda. Licensed under the Creative Commons 3.0 Attributions license.
Goroutine͕͋Δ ※ݸਓతͳײͰ͢
Goroutineʁ
Goroutine • GoͰฒߦ࣮ߦΛ࣮ݱ͢ΔΈͰɺฏͨ͘ݴ͏ͱεϨουΈ ͍ͨͳײ͡ • Goroutine͕͋Δ͚ͩͰฒྻॲཧ͕ॻ͖͍͢
Tour of Go #63 package main import ( "fmt" "time"
) func say(s string) { for i := 0; i < 5; i++ { time.Sleep(100 * time.Millisecond) fmt.Println(s) } } func main() { go say("world") say("hello") }
಄ʹgoΛ͚ͭͯݺͿ͚ͩ func main() { go say("world") say("hello") } ͜Ε͚ͩͰผεϨουͰ࣮ߦͰ͖·͢
Goͷ͓͠·͍
͡Ό͋Pythonͷฒྻॲ ཧʁ
PythonͰͷฒྻॲཧ • multiprocessing • concurrent.futures • asyncio etc...
PythonͰͷฒྻॲཧ • multiprocessing • concurrent.futures • asyncio etc...
asyncio asyncio - ඇಉظ I/OɺΠϕϯτϧʔϓɺίϧʔνϯ͓ΑͼλεΫ • Python3.4ͰՃ͞ΕͨඇಉظI/Oͳඪ४ϥΠϒϥϦ • Python3.3Ͱ༻Մೳ #
pip install asyncio • PyConJP 2014Ͱηογϣϯ͕͋Γ·ͨ͠ɻ • PythonʹΑΔඇಉظϓϩάϥϛϯάೖ (ja)
αϯϓϧ
import asyncio import random @asyncio.coroutine def wait_for(task_name): wait = random.randint(1,
5) print('taks {} begin. wait {} sec'.format(task_name, wait)) yield from asyncio.sleep(wait) print('taks {} end.'.format(task_name)) def main(): tasks = [wait_for(x) for x in range(3)] loop = asyncio.get_event_loop() loop.run_until_complete(asyncio.wait(tasks)) loop.stop() if __name__ == '__main__': main()
Πϕϯτϧʔϓ࡞ͬͯɺίϧʔνϯ࡞ͬͯݺͼग़ͤฒྻॲཧ͕ Ͱ͖ͦ͏
͜·͚͍͍͐ͨ͊͜ΜͩΑʂʂ (AAུ
ࠓճΓ͔ͨͬͨ͜ͱ
http://d.hatena.ne.jp/heavenshell/20120304
asyncioΛͬͨ2015 ൛Λʂ
ͬͯΈͨ
σϞ https://gist.github.com/mursts/1709f01572365a98d057
໌(20159݄13)ԿͷͰ͠ΐ͏͔ʁ
Python3.5ϦϦʔε(༧ఆ)ʂ
None
None
import asyncio async def co_func1(): return 'co_func1_ok' async def co_func2():
return await co_func1() + ' co_func2_ok' loop = asyncio.get_event_loop() print(loop.run_until_complete(co_func2())) # co_func1_ok co_func2_ok Python3.5͔Βಋೖ͞ΕΔasyncͱawaitͰίϧʔνϯΛѻ͏ - Qiita
3.5Ͱasyncioͷվྑೖ͍ͬͯΔΑ͏ͳͷͰɺͥͻ3.5Ͱͬ ͯΈ·͠ΐ͏ Python3.4 ͷ৽ػೳ asyncio ΛͬͯΈΔ
3.5Ͱಋೖ͞ΕΔܕώϯτָ͠ΈͰ͢
͝੩ௌ͋Γ͕ͱ͏͍͟͝ ·ͨ͠