I have observed some "odd" behaviour with SimPy event scheduling.
When a nan value, is used as the delay in the env.timeout
method, it sometimes, overwrites the until = XXX
parameter inside the env.run
method.
I have outlined a minimal example, to show the inconsistent behaviour of this. If you run all 3 test cases, you will see test 2 runs forever.
Looking through the source code, it appears to be some interaction between, timeout and scheduling, but have not got further than this.
Q: Could someone help me understand, why the until
parameter is overwritten when, in a specific order, null values are entered in the timout
method?
import simpy
import numpy as np
# Set up a minimal SimPy process
def func1(env, time, name):
while True:
print(f'process: {name}, delayed for {time}, time:', env.now)
# print(env._queue)
# print('================')
yield env.timeout(time)
def test_one():
"""Stops after 20 days - Normal process at the start"""
env = simpy.Environment()
env.process(func1(env = env, time = 2, name = '3'))
env.process(func1(env = env, time = np.nan, name = '2'))
env.process(func1(env = env, time = np.nan, name = '1'))
env.process(func1(env = env, time = np.nan, name = '3'))
env.run(until = 20)
def test_two():
"""Runs forever - Normal process at the end"""
env = simpy.Environment()
env.process(func1(env = env, time = np.nan, name = '2'))
env.process(func1(env = env, time = np.nan, name = '1'))
env.process(func1(env = env, time = np.nan, name = '3'))
env.process(func1(env = env, time = 2, name = '3'))
env.run(until = 20)
def test_three():
"""Stops after 20 days - Normal process in 2nd position"""
env = simpy.Environment()
env.process(func1(env = env, time = np.nan, name = '2'))
env.process(func1(env = env, time = 2, name = '3'))
env.process(func1(env = env, time = np.nan, name = '1'))
env.process(func1(env = env, time = np.nan, name = '3'))
env.run(until = 20)