Last active
February 6, 2016 01:53
-
-
Save paulohrpinheiro/a28af1fcf4bcdb6828da to your computer and use it in GitHub Desktop.
Quantos números pseuso-aleatórios posso gerar em um segundo?
This file contains 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
import random | |
import signal, os | |
# Xupinskado de https://docs.python.org/2/library/signal.html#signal.setitimer | |
def handler(signum, frame): | |
print('Acabando....', signum) | |
raise NameError("Acaboooooouuuuuuuuu!!!!") | |
# Set the signal handler and a 1-second alarm | |
signal.signal(signal.SIGALRM, handler) | |
signal.alarm(1) | |
quantos = 0 | |
try: | |
while(True): | |
random.randrange(100) | |
quantos+=1 | |
except: | |
signal.alarm(0) # Disable the alarm | |
print(quantos) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment