-
Notifications
You must be signed in to change notification settings - Fork 23
/
testAsync.py
36 lines (28 loc) · 929 Bytes
/
testAsync.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import guy,asyncio,time
class asyncTest(guy.Guy):
__doc__="""
<style> body.wsguy {background:yellow} </style>
<script>
function rep(x) {
document.getElementById("rep").innerHTML="<li>"+x+"</li>"+document.getElementById("rep").innerHTML;
}
</script>
<button onclick="self.doSyncQuick().then(rep)">sync quick</button>
<button onclick="self.doSyncLong().then(rep)">sync long (block ui)</button>
<button onclick="self.doASyncLong().then(rep)">async long</button>
<div id="rep"></div>
"""
size=(200,200)
def doSyncQuick(self):
return "quick"
def doSyncLong(self): # run synchro (hangs the ui)
time.sleep(3)
return "long"
async def doASyncLong(self): # run asynchro !!! (it doesn't hang the UI !)
await asyncio.sleep(3)
return "async long"
if __name__=="__main__":
app=asyncTest()
app.run()