Attempt to fix issue with slow unpickling..

This commit is contained in:
Dima Gerasimov 2018-11-16 22:33:51 +00:00
parent cb39e5a00e
commit 930bf099a3
2 changed files with 6 additions and 6 deletions

View file

@ -63,10 +63,12 @@ def load_locations() -> Iterator[Location]:
) )
def iter_locations(cached: bool=False) -> Iterator[Location]: def iter_locations(cached: bool=False) -> Iterator[Location]:
import dill # type: ignore import sys
sys.path.append('/L/Dropbox/data/location_provider') # jeez.. otherwise it refuses to unpickle :(
import pickle as dill # type: ignore
if cached: if cached:
with open(CACHE_PATH, 'rb') as fo: with open(CACHE_PATH, 'rb') as fo:
# TODO while fo has more data?
while True: while True:
try: try:
pre = dill.load(fo) pre = dill.load(fo)
@ -168,9 +170,8 @@ def get_groups(cached: bool=False) -> List[LocInterval]:
dump_group() dump_group()
return groups return groups
# TODO ok, def cache groups.
def update_cache(): def update_cache():
import dill # type: ignore import pickle as dill # type: ignore
CACHE_PATH_TMP = CACHE_PATH + '.tmp' CACHE_PATH_TMP = CACHE_PATH + '.tmp'
# TODO maybe, also keep on /tmp first? # TODO maybe, also keep on /tmp first?
with open(CACHE_PATH_TMP, 'wb', 2 ** 20) as fo: with open(CACHE_PATH_TMP, 'wb', 2 ** 20) as fo:

View file

@ -18,6 +18,5 @@ if len(sys.argv) > 1:
raise RuntimeError(f"Unknown command {cmd}") raise RuntimeError(f"Unknown command {cmd}")
else: else:
for p in get_groups(cached=True): for p in get_groups(cached=True):
pass print(p)
# TODO need datetime! # TODO need datetime!
# print(p)