blob: 8d31dd8004598cb5e8f2dad7e5ea5e680ea6c1ad (
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
|
import asyncio
import sys
import os
sys.path.append(os.path.expanduser('~/nemesis/'))
from nemesis.causal_event_loop import causal_loop_factory
import time
async def burn_cpu(sec):
t0 = time.perf_counter()
elapsed = 0
while (elapsed < sec):
for _ in range(1000):
pass
elapsed = time.perf_counter() - t0
async def sleep_task(duration):
await asyncio.create_subprocess_shell(f'sleep {duration}')
async def main():
total_duration = 90
sleep_durations = [1.0, 0.4, 0.7, 0.7]
for _ in range(total_duration):
tasks = [asyncio.create_task(sleep_task(duration)) for duration in sleep_durations]
burn_task = asyncio.create_task(burn_cpu(1))
await asyncio.gather(burn_task, *tasks)
asyncio.run(main(), loop_factory=causal_loop_factory)
|