Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
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
460
お金ダッシュボードを作ってみた
mursts
0
340
FlaskとYomanでHello World
mursts
0
400
Google App Engine入門
mursts
0
660
Other Decks in Technology
See All in Technology
2026TECHFRESH畢業分享會 - Lightning Talk - 打造精準高效的 MCP 設計模式與測試實務
line_developers_tw
PRO
0
870
AI駆動開発を通して感じた、 AI時代のデザイナーの役割変化
whisaiyo
1
1.3k
作って終わりにしない タイミーのセマンティックレイヤー育成の現在地
chanyou0311
4
2.2k
Amazon Bedrock AgentCore ワークショップ JAWS UG TOHOKU / amazon-bedrock-agentcore-workshop-jawsug-tohoku-2026
gawa
9
750
新しいVibe Codingと”自走”について
watany
6
300
チームで進めるAI駆動アジャイル×ウォーターフォール
kumaiu
0
150
2026TECHFRESH畢業分享會 - AI 時代的人生存檔點
line_developers_tw
PRO
0
870
MCP Appsを作ってみよう
iwamot
PRO
4
560
FinOps × AIエージェントで実現する コストインシデントの自動調査
oasis1994liveforever
0
130
[モダンアプリ勉強会]今更聞けないGit/GitHub入門
tsukuboshi
0
370
AI-DLCを活用した高品質・安全なAI駆動開発実践 / AI Driven Development with AI-DLC
yoshidashingo
0
170
AGENTS.mdとSkillsで始めるAIエージェント活用
sonoda_mj
3
200
Featured
See All Featured
Producing Creativity
orderedlist
PRO
348
40k
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
840
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
Designing Powerful Visuals for Engaging Learning
tmiket
1
410
The SEO Collaboration Effect
kristinabergwall1
1
480
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.8k
Docker and Python
trallard
47
3.9k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.3k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
310
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
4k
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
190
Discover your Explorer Soul
emna__ayadi
2
1.1k
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Ͱಋೖ͞ΕΔܕώϯτָ͠ΈͰ͢
͝੩ௌ͋Γ͕ͱ͏͍͟͝ ·ͨ͠