I am still quite new to python. Lately, playing with simpy module I encountered some strange behaviour by python interpreter. I implemented .flood() function and it is supposed to be a part of simulation. To my surprise, the debug inside of it was not shown on the console. Inside of this function are two major chunks of code, so I decided to erase one of them (containing while True: loop).
print("Starting program")
env = simpy.Environment()
#From now on we assume the nodes to be 0-indexed
#Create two routers we will connect manually
routers = [Router(env, i, debug = True) for i in range(3)]
# Create wire connection between routers
for i in range(2):
addConnection(env, routers[i], routers[i + 1])
for router in routers:
print("Line above .flood() call")
router.flood()
env.run(until = 100)
def flood(self):
print(f"beginning to flood at {self.env.now}")
for wire in self.out_wire:
wire.put(Packet(self.env.now,
random.randint(1, 10**9),
{"node": self.id, "neigh":self.neighbors}))
while True:
processes = [nei.get() for nei in self.in_wire]
res = yield simpy.events.AnyOf(self.env, processes)
print("RESULT: ", res, f"current time is {self.env.now}")
for packet in res:
print(packet)
Running this code produces:
Starting program
Line above .flood() call
Line above .flood() call
Line above .flood() call
When I comment while True: part, then the output is as follows:
Starting program
Line above .flood() call
beginning to flood at 0
Line above .flood() call
beginning to flood at 0
Line above .flood() call
beginning to flood at 0
Now I am wondering what have I done wrong? I am aware, that my simulation is still not working, and probably I am doing something not too smart there, but other than this did anyone ever see something similar?