-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
40 lines (30 loc) · 885 Bytes
/
test.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
33
34
35
36
37
38
39
40
from src.board import Board
from src.ai import get_best_move
import asyncio
import time
def run_asynchronously(func_, *args, **kwargs):
"""Makes any function run asynchronously
avoiding the RuntimeError that can come
"""
try:
loop = asyncio.get_running_loop()
except RuntimeError: # 'RuntimeError: There is no current event loop...'
loop = None
if loop and loop.is_running():
print("loop created")
task = loop.create_task(func_(*args, **kwargs))
loop.run_until_complete(task)
else:
asyncio.run(func_(*args, **kwargs))
def time_(function_, *args, **kwargs):
start_time = time.time()
print(function_(*args, **kwargs))
print(time.time() - start_time)
def run():
board = Board()
return run_asynchronously(
get_best_move,
board,
True,
)
print(time_(run))