How to run several looping functions at the same time in python? -


i've been working on project assigned do. sort of parking lot cars enter, generated automaticly (done) now, i've put them 'waiting list (because have represent them gui module later) in order later assigned in spot in parking lot. , must out parking lot (also randomly)

the problem raises when created function create cars randomly, cant call other function because first 1 looping.

the question is, there way call several looping functions @ same time?

thanks

the question is, there way call several looping functions @ same time?

this great question , there several ways it.

threading can let functions run concurrently. data flow between threads should managed using queue module:

# inter-thread communication wait_to_park = queue() wait_to_exit = queue()  # start simulation tg = threading.thread(target=generate_cars) tp = threading.thread(target=park_cars) tu = threading.thread(target=unpark_cars) tg.start(); tp.start(); tu.start()  # wait simumlation finish tg.join() wait_to_park.join() tp.join() wait_to_exit.join() tu.join() 

alternatively, can use event-loop such sched module coordinate events. generators may -- work functions can suspended , restarted.


Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -