Flaky RealtimeEnvironment doctest on macOS
Sometimes the following happens:
=================================== FAILURES ===================================
_____________________ [doctest] real-time-simulations.rst ______________________
041 >>>
042 >>> env = simpy.Environment()
043 >>> proc = env.process(example(env))
044 >>> env.run(until=proc)
045 Duration of one simulation time unit: 0.00s
046 >>>
047 >>> import simpy.rt
048 >>> env = simpy.rt.RealtimeEnvironment(factor=0.1)
049 >>> proc = env.process(example(env))
050 >>> env.run(until=proc)
Expected:
Duration of one simulation time unit: 0.10s
Got:
Duration of one simulation time unit: 0.11s
If you run the following code on macOS, you may observe 105ms sleeps with 100ms requested, which round up to 0.11s:
import time
for _ in range(50):
start = time.time()
time.sleep(0.1)
elapsed = time.time() - start
print("elapsed = {:.3f}ms".format(elapsed * 1000))
$ python wtf.py
elapsed = 105.054ms
elapsed = 104.674ms
elapsed = 105.063ms
elapsed = 103.843ms
elapsed = 105.033ms
elapsed = 105.142ms
...
This seems more prevalent on macOS Big Sur, but also seems to happen on Catalina. I don't have access to anything older to see if it was any different. Linux inside of QEMU on macOS also experiences this.