Helo, 저는 SimPy에서 비교적 복잡한 Discrete Event Simulation 모델을 만들고 있습니다.Python, SimPy : 함수 내에서 yield 사용하기
내 yield 문을 함수에 넣으려고하면 프로그램이 작동하지 않는 것 같습니다. 아래는 예를 보여줍니다.
0 activate <Klaus > at time: 1.0 prior: False
1.0 hold <Klaus> delay: 2.0
3.0 <Klaus > terminated
holdLong()와 holdShort 방법은 전혀 작동하지 않았다
import SimPy.SimulationTrace as Sim
import random
## Model components ##
class Customer(Sim.Process):
def visit(self):
yield Sim.hold, self, 2.0
if random.random()<0.5:
self.holdLong()
else:
self.holdShort()
def holdLong(self):
yield Sim.hold, self, 1.0
# more yeild statements to follow
def holdShort(self):
yield Sim.hold, self, 0.5
# more yeild statements to follow
## Experiment data ##
maxTime = 10.0 #minutes
## Model/Experiment ##
#random.seed(12345)
Sim.initialize()
c = Customer(name = "Klaus") #customer object
Sim.activate(c, c.visit(), at = 1.0)
Sim.simulate(until=maxTime)
내가 이것을 실행에서 얻을 출력이다. 이 문제를 어떻게 해결할 수 있습니까? 미리 감사드립니다.
파이썬 3.3의 새로운 'yield from'구문이 여기 유용 할 것 같습니다. – jomido