File size: 1,130 Bytes
f3f259e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import aiohttp
import asyncio

async def post_request(session, url, headers, json_data):
    async with session.post(url, headers=headers, json=json_data) as response:
        response_text = await response.text()
        print(response_text)
        return response_text

async def main(concurrent_requests):
    url = 'http://127.0.0.1:8000/runcode'
    headers = {
        'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
        'Content-Type': 'application/json',
        'Authorization': 'Bearer 114514',
        'Accept': '*/*',
        'Host': '127.0.0.1:8000',
        'Connection': 'keep-alive'
    }
    json_data = {
        "languageType": "python",
        "variables": {},
        "code": "```python\nimport time\nprint('Hello from code block!')\ntime.sleep(3)\n```"
    }

    async with aiohttp.ClientSession() as session:
        tasks = [post_request(session, url, headers, json_data) for _ in range(concurrent_requests)]
        await asyncio.gather(*tasks)

if __name__ == '__main__':
    concurrent_requests = 5  # 设置并发数
    asyncio.run(main(concurrent_requests))