【发布时间】:2018-04-14 16:37:26
【问题描述】:
我有多个进程,每个进程都有其适当的存储,它将以随机的时间间隔与单个进程通信。因为我使用了 Environment.any_of(all_stores.get()),这将返回一个字典,其中键是 StoreGet 对象,值是商店中的值。
我希望有一种方法可以知道字典中的每个条目对应的商店(如果不可能,则处理)。
import simpy,random
def worker(ident,env,sstore):
while True:
yield env.timeout(random.randint(0,10))
# calculation
sstore.put(random.random())
def mon(env,lstores):
while True:
resultat=yield env.any_of([s.get() for s in lstores])
# calculation depending of the values and the source
# need to know the source of each information
env=simpy.Environment()
lstores=[simpy.Store(env,capacity=1) for x in range(5)]
lworkers=[env.process(worker((i+1),env,lstores[i])) for i in range(5)]
env.process(mon(env,lstores))
env.run(until=30)
【问题讨论】:
标签: python python-3.x simpy