コード例 #1
0
    def test_await_raises_exception(self):
        async def a(arg):
            raise RuntimeError('foo')

        with pytest.raises(RuntimeError) as exc:
            await_(a(42))
        assert exc.type == RuntimeError
        assert str(exc.value) == 'foo'
コード例 #2
0
    def add_and_select_data(conn, data):
        row = await_(
            conn.fetchrow("insert into mytable(data) values ($1) returning id",
                          data))
        id_ = row[0]
        result = await_(
            conn.fetchrow("select data from mytable where id=($1)", id_))

        return result[0]
コード例 #3
0
    def test_await_function_with_internal_loop(self):
        var = None

        async def a(arg):
            nonlocal var
            var = arg
            return arg

        ret = await_(a(42))
        assert ret == 42
        assert var == 42

        bridge.stop()
        assert not bridge.running
        assert not asyncio.get_event_loop().is_running()
コード例 #4
0
    async def __call__(self, scope, receive, send):
        if scope["type"] != "http":
            raise ValueError("WSGI wrapper received a non-HTTP scope")
        self.scope = scope
        with SpooledTemporaryFile(max_size=65536) as body:
            # Alright, wait for the http.request messages
            while True:
                message = await receive()
                if message["type"] != "http.request":
                    raise ValueError(
                        "WSGI wrapper received a non-HTTP-request message")
                body.write(message.get("body", b""))
                if not message.get("more_body"):
                    break
            body.seek(0)

            # Wrap send so it can be called from the subthread
            self.sync_send = await_(send)
            # Call the WSGI app
            await self.run_wsgi_app(body)
コード例 #5
0
ファイル: endpoints.py プロジェクト: PompaJokera/core
async def delete_sensor(sensor_id: int = None):
    await_(delete_sensor_from_db(sensor_id))
    return {"STATUS": "OK"}
コード例 #6
0
def t():
    for i in range(1000):
        await_(asyncio.sleep(random.random() / 1000))
コード例 #7
0
 def b():
     nonlocal var
     await_(asyncio.sleep(0.01))
     var += 2
     return var
コード例 #8
0
 def b(arg):
     return await_(a(arg))
コード例 #9
0
async def add_new_humidity(sensor_id: int, req: HumidityRequest):
    await_(add_humidity_to_db(req, sensor_id))
    return {"STATUS": "OK"}
コード例 #10
0
ファイル: test_core.py プロジェクト: moriyoshi/greenletio
 def b(arg):
     with pytest.raises(RuntimeError) as error:
         await_(a(arg))
     assert type(error.value) == RuntimeError and \
         str(error.value) == '42'
コード例 #11
0
def main():
    for i in range(10):
        await_(asyncio.sleep(random.random()))
        print(i)