import asyncio import httpx import time async def do_work_async(): http = httpx.AsyncClient() while True: resp = await http.get('https://httpbin.org/status/202') print(f'async: {resp.status_code}') await asyncio.sleep(0.5) async def do_work_sync(): http = httpx.Client() while True: resp = http.get('https://httpbin.org/status/202') print(f'sync: {resp.status_code}') time.sleep(0.5) async def main(): t = asyncio.create_task(do_work_async()) await asyncio.sleep(5) await do_work_sync() if __name__ == '__main__': asyncio.run(main())