Last active
October 13, 2022 17:01
-
-
Save duducp/b16bf179bbdec6b03925c77383173d4e to your computer and use it in GitHub Desktop.
Semáforo em Python
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 threading import Semaphore, Thread | |
from time import sleep | |
# Número máximo de threads a serem execultadas simultaneamente | |
control_threads = Semaphore(5) | |
def view_log(number: int): | |
with control_threads: | |
print(f'O número atual é: {number}') | |
sleep(5) | |
# Perceba que iremos faze rum loop 20x | |
# mais a cada 5x terá uma pausa de 5 segundos | |
for number in range(20): | |
thread = Thread( | |
target=view_log, | |
args=[number] | |
) | |
thread.start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i dont understand