Created
August 20, 2018 12:29
-
-
Save guangrei/7ff6a460a635cd357e993944f35d536c to your computer and use it in GitHub Desktop.
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
from typing import NoReturn | |
import asyncio | |
import time | |
from random import randint | |
nilai: int = 0 | |
start: int = time.time() | |
async def simulasiProg() -> NoReturn: | |
global nilai | |
while True: | |
print("nilai: ",nilai) | |
num: int = randint(1,5) | |
await asyncio.sleep(num) | |
nilai = nilai + 1 | |
async def timer() -> NoReturn: | |
global start | |
global nilai | |
while True: | |
await asyncio.sleep(0.1) | |
end: int = time.time() | |
delta: int = end - start | |
if delta >= 60: | |
nilai = 0 | |
print("nilai telah direset") | |
start = time.time() | |
loop: asyncio.Task = asyncio.get_event_loop() | |
try: | |
asyncio.ensure_future(timer()) | |
asyncio.ensure_future(simulasiProg()), | |
loop.run_forever() | |
except KeyboardInterrupt: | |
pass | |
finally: | |
print("menghentikan program") | |
loop.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment