-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
39 lines (29 loc) · 874 Bytes
/
utils.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
# coding: utf8
from __future__ import print_function
import json
from argparse import ArgumentParser
from threading import Event, Thread
try:
from typing import Any, Callable
except ImportError:
pass
def argparse_worker():
# type: () -> tuple
parser = ArgumentParser()
parser.add_argument(
"--settings", "-s", help=u"путь до файла с настройками", required=True
)
args, unknown = parser.parse_known_args()
return args, unknown
def read_config(filename):
# type: (str) -> dict
with open(filename) as config_file:
return json.load(config_file)
def call_repeatedly(interval, func, *args):
# type: (float, Callable, *Any) -> Event
stopped = Event()
def loop():
while not stopped.wait(interval):
func(*args)
Thread(target=loop).start()
return stopped