Skip to content

Instantly share code, notes, and snippets.

@duducp
Last active October 13, 2022 17:01
Show Gist options
  • Save duducp/b16bf179bbdec6b03925c77383173d4e to your computer and use it in GitHub Desktop.
Save duducp/b16bf179bbdec6b03925c77383173d4e to your computer and use it in GitHub Desktop.
Semáforo em Python
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()
@oscdev11
Copy link

i dont understand

@oscdev11
Copy link

Can explain more plis?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment