-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path07-invoke-async.py
More file actions
executable file
·60 lines (43 loc) · 1.56 KB
/
07-invoke-async.py
File metadata and controls
executable file
·60 lines (43 loc) · 1.56 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python3
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public License
# as published by the Free Software Foundation; either version 2.1
# of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
import sys
import pyquid
import time
success = False
def on_invocation_done(value, user_data):
global success
global my_user_data
assert value == 'hello world and count is 0'
assert user_data == my_user_data
success = True
# create a switcher.
sw = pyquid.Switcher('pyquid', debug=True)
# creating a quiddity method-quid in order to illustrate method invocation
methodquid = sw.create('method-quid')
# some Quiddities has methods that can be invoked
assert 'hello world and count is 0' == methodquid.invoke('hello', ['world'])
# asynchronous invocation invoke_async
my_user_data = ["my", "user", "data"]
methodquid.invoke_async('hello', ['world'], on_invocation_done, my_user_data)
# wait 200 milliseconds
time.sleep(0.2)
# check error
try:
methodquid.invoke("nonexistent method")
except RuntimeError:
pass
try:
methodquid.invoke_async("nonexistent method", ['world'], on_invocation_done, my_user_data)
except RuntimeError:
pass
if success == True:
exit(0)
# fail if invocation done has not been notified
exit(1)