blob: 4392b2216b11a14fd76e091df33f05b90fa59ebf (
plain)
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
61
62
63
64
65
66
67
68
69
70
71
|
#
# Copyright (c) ZeroC, Inc. All rights reserved.
#
import asyncio
import Ice
import Test
# The implementation of the coroutines below assume the use of an Ice dispatcher which
# dispatch the calls on an asyncio event loop
class TestIntfI(Test.TestIntf):
async def op(self, current):
# make sure this is called from an asyncio event loop
asyncio.get_running_loop()
# ensure that returning the result from the coroutine without await works
return 5
async def throwUserException1(self, current):
# make sure this is called from an asyncio event loop
asyncio.get_running_loop()
# ensure that raising the exception from the coroutine without await works
raise Test.TestException()
async def throwUserException2(self, current):
# make sure this is called from an asyncio event loop
asyncio.get_running_loop()
# ensure that raising the exception after from the coroutine after the await works
await asyncio.sleep(0.01)
raise Test.TestException()
async def throwUnhandledException1(self, current):
# make sure this is called from an asyncio event loop
asyncio.get_running_loop()
# ensure that raising an unhandled exception from the coroutine without await works
raise Exception("unexpected")
async def throwUnhandledException2(self, current):
# make sure this is called from an asyncio event loop
asyncio.get_running_loop()
# ensure that raising an unhandled exception from the coroutine after the await works
await asyncio.sleep(0.01)
raise Exception("unexpected")
async def sleep(self, ms, current):
# make sure this is called from an asyncio event loop
asyncio.get_running_loop()
# ensure that awaiting before returning the result works
await asyncio.sleep(ms / 1000.0)
async def callOpOn(self, proxy, current):
# make sure this is called from an asyncio event loop
asyncio.get_running_loop()
# ensure that awaiting proxy invocations works
await Ice.wrap_future(proxy.sleepAsync(10))
return await Ice.wrap_future(proxy.opAsync())
def shutdown(self, current=None):
# make sure this is called from an asyncio event loop
asyncio.get_running_loop()
current.adapter.getCommunicator().shutdown()
|