Wake up the geek way!

Gael Pasgrimaud @gawel_

PSES 2015

About me

3615-2.0 Ma vie

Skate

images/skate.jpg

La bougeotte

Du coup...

Sunset

images/sunset.jpg

Résultat

Surf

images/surfbikerack2.jpg

asyncio

Module introduit dans python3.4 permettant l’asynchrone sans de code spaghetti

Async

images/async.png

Qu’est ce que le spaghetti?

Javascript!

Des callback de callback de callback

$.get('/', function(data) {
    $.post('/', function(data) {
        setTimeout(function() { $.get('/timeout', function(data) {
            ...
            }, 1000)
        }
    }
}

Avec asyncio

Pas de callback. Lecture linéaire compréhensible.

resp = yield from http.get('/')
resp = yield from http.post('/', (yield from resp.body))
yield from asyncio.sleep(.1)
resp = yield from http.get('/timeout')

Cas d’utilisation

Le meilleur réveil du monde

Dans la vrai fausse vie

images/irssi.jpg

Et le matin

2015-06-12 09:00:00 INFO alarm matin launched
2015-06-12 09:00:00 INFO ison {'names': ['gawel']}
2015-06-12 09:00:00 INFO whois {'idle': '31821', ...}
2015-06-12 09:00:00 INFO Ring matin for gawel
2015-06-12 09:00:01 INFO irc3.alarm.gawel is ringing
2015-06-12 09:00:16 INFO Hangup <Message ...> after 15s
2015-06-12 09:00:16 INFO irc3.alarm.gawel is ringing
2015-06-12 09:00:16 INFO Hangup <Message ...> after 0s

Check le pseudo, l’idle, puis sonne. Raccroche au bout de 15s.

Ne réveille pas si on est réveillé. Tadaah!