File: client

package info (click to toggle)
python-orjson 3.10.7-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,180 kB
  • sloc: ansic: 11,270; python: 6,658; sh: 135; makefile: 9
file content (33 lines) | stat: -rwxr-xr-x 619 bytes parent folder | download
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
#!/usr/bin/env python3

import asyncio
import sys
import time

import httpx

port = sys.argv[1]
url = f"http://127.0.0.1:{port}"

timeout = httpx.Timeout(5.0)
client = httpx.AsyncClient(timeout=timeout)

stop_time = time.time() + 5

TEST_MESSAGE = "http test running..."


async def main():
    sys.stdout.write(TEST_MESSAGE)
    sys.stdout.flush()
    count = 0
    while time.time() < stop_time:
        res = await client.get(url)
        count += 1
    sys.stdout.write(f"\r{TEST_MESSAGE} ok, {count} requests made\n")


loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
asyncio.run(main())
loop.close()