forked from kubadlugosz/algorithmic-trading
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtime.py
32 lines (26 loc) · 976 Bytes
/
time.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# =============================================================================
# python time module
# Author : Mayank Rasu
# Please report bug/issues in the Q&A section
# =============================================================================
import time
import numpy as np
def fibonacci(n):
"""Recursive function to print nth Fibonacci number"""
if n <= 1:
return n
else:
return(fibonacci(n-1) + fibonacci(n-2))
def main():
num = np.random.randint(1,25)
print("%dth fibonacci number is : %d"%(num,fibonacci(num)))
# Continuous execution
starttime=time.time()
timeout = time.time() + 60*2 # 60 seconds times 2 meaning the script will run for 2 minutes
while time.time() <= timeout:
try:
main()
time.sleep(5 - ((time.time() - starttime) % 5.0)) # 5 second interval between each new iteration
except KeyboardInterrupt:
print('\n\nKeyboard exception received. Exiting.')
exit()