1

I am using SimPy for a time-based simulation.

I have a Messager process which listens for a specific event, and returns the parameters of that event when it occurs:

class Messager(Process):
    def __init__(self):
        Process.__init__(self,'messager')

    def monitor(self):
        while True:
            yield waitevent, self, messageEvent
            print messageEvent.signalparam

messager = Messager()
activate(messager,messager.monitor())

this works fine. However, in reality there is more than one Event which should be handled by the Messager, and I want the Messager to return the signalparam for the causative Event in a list of events:

messageEvents = [Event1,Event2,Event3]

class Messager(Process):
    def __init__(self):
        Process.__init__(self,'messager')

    def monitor(self):
        while True:
            yield waitevent, self, messageEvents
            .....

how do I access the signalparam of the Event which has occurred?

4

1 回答 1

0

查看 simpy 的源代码,特别是 Simevent 类,如果您可以以某种方式将事件转换为 Simevent 类,那么您应该能够从中获取属性信号参数。不确定这是否可行,但希望您知道一种方法。祝你好运。

编辑:也想到了这一点,您可以编辑您的 simpy 并使 Simevent 类具有获取信号参数的功能。仅供参考,如果您想这样做,simevent 类位于 lib.py 文件中。

于 2012-09-25T07:00:24.433 回答