Last active
April 16, 2020 14:17
-
-
Save ppsirg/f3702c502933b43ef6268e7ce72d31a6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from concurrent.futures import ThreadPoolExecutor | |
from time import sleep, time | |
def runner(state, working, wait_to_start): | |
print(f'start {state}') | |
sleep(wait_to_start * 60) | |
stop_time = time() + (working * 60) | |
while stop_time >= time(): | |
print(state) | |
sleep(0.2) | |
def main(): | |
estados = [ | |
('a', 2, 0), | |
('b', 4, 1), | |
('c', 4, 30) | |
] | |
with ThreadPoolExecutor(max_workers=len(estados)+1) as pool: | |
pool_futures = [] | |
for state, working, wait_to_start in estados: | |
f = pool.submit(runner, state, working, wait_to_start) | |
pool_futures.append(f) | |
while not all(map(lambda x: x.done(), pool_futures)): | |
sleep(0.1) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment