asyncio

PyUGAT
February 23rd, 2014
What is asynchronous I/O?
●

Input and output operations: slooooow
–

●

●

Disks, network, SSD,

Blocking I/O: wait for I...
Asynchronous I/O in Python
●

asyncore and asynchat modules, select module
–
–

●

inflexible API, too simplistic
select: ...
asyncio
●

== Tulip

●

Will be in standard library (Python 3.4)

●

Python 3.3: pip install asyncio
yield from
(PEP 380)
for x in subgenerator:
    yield x
_i = iter(EXPR)
try:
    _y = next(_i)
except StopIteration as _e:
    _r = _e.value
else:
    while 1:
        try:
     ...
RESULT = yield from EXPR
asyncio
●

Event loop

●

Tasks and coroutines

●

Transports and protocols
Code
Upcoming SlideShare
Loading in …5
×

asyncio

414 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
414
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

asyncio

  1. 1. asyncio PyUGAT February 23rd, 2014
  2. 2. What is asynchronous I/O? ● Input and output operations: slooooow – ● ● Disks, network, SSD, Blocking I/O: wait for I/O operation to complete Non-blocking I/O: permits other processing to continue before I/O operation has finished ● Non-blocking I/O == asynchronous I/O ● Platform-dependent low-level APIs – e.g. epoll (Linux), I/O Completion Ports (Windows, Solaris), kqueue (BSD, Mac OS X), ...
  3. 3. Asynchronous I/O in Python ● asyncore and asynchat modules, select module – – ● inflexible API, too simplistic select: only partial support on Windows Existing frameworks: – Twisted (https://twistedmatrix.com/trac/) – Gevent (http://www.gevent.org/) ● Monkey-patching – Tornado (http://www.tornadoweb.org/) – Lack of compatibility
  4. 4. asyncio ● == Tulip ● Will be in standard library (Python 3.4) ● Python 3.3: pip install asyncio
  5. 5. yield from (PEP 380)
  6. 6. for x in subgenerator:     yield x
  7. 7. _i = iter(EXPR) try:     _y = next(_i) except StopIteration as _e:     _r = _e.value else:     while 1:         try:             _s = yield _y         except GeneratorExit as _e:             try:                 _m = _i.close             except AttributeError:                 pass             else:                 _m()             raise _e         except BaseException as _e:             _x = sys.exc_info()             try:                 _m = _i.throw             except AttributeError:                 raise _e             else:                 try:                     _y = _m(*_x)                 except StopIteration as _e:                     _r = _e.value                     break         else:             try:                 if _s is None:                     _y = next(_i)                 else:                     _y = _i.send(_s)             except StopIteration as _e:                 _r = _e.value                 break RESULT = _r
  8. 8. RESULT = yield from EXPR
  9. 9. asyncio ● Event loop ● Tasks and coroutines ● Transports and protocols
  10. 10. Code

×