add try/except block around subprocess
This commit is contained in:
parent
1172405994
commit
0e6067ffe3
2 changed files with 28 additions and 23 deletions
|
@ -1,6 +1,6 @@
|
||||||
import json
|
import json
|
||||||
from site_api import get, api, replay
|
from site_api import get, api, replay
|
||||||
from sat import COLORS, solve_sat
|
from sat import solve_sat
|
||||||
from database import Game, store, load, commit, conn
|
from database import Game, store, load, commit, conn
|
||||||
from download_data import export_game
|
from download_data import export_game
|
||||||
from variants import num_suits, VARIANTS, variant_name
|
from variants import num_suits, VARIANTS, variant_name
|
||||||
|
@ -144,31 +144,35 @@ def solve_instance(num_players, deck):
|
||||||
|
|
||||||
|
|
||||||
def solve_seed(seed, num_players, deck_compressed, var_id):
|
def solve_seed(seed, num_players, deck_compressed, var_id):
|
||||||
deck = decompress_deck(deck_compressed)
|
try:
|
||||||
t0 = perf_counter()
|
deck = decompress_deck(deck_compressed)
|
||||||
solvable, solution, num_remaining_cards = solve_instance(num_players, deck)
|
t0 = perf_counter()
|
||||||
t1 = perf_counter()
|
solvable, solution, num_remaining_cards = solve_instance(num_players, deck)
|
||||||
logger.info("Solved instance {} in {} seconds".format(seed, round(t1-t0, 2)))
|
t1 = perf_counter()
|
||||||
|
logger.info("Solved instance {} in {} seconds".format(seed, round(t1-t0, 2)))
|
||||||
|
|
||||||
mutex.acquire()
|
mutex.acquire()
|
||||||
if solvable is not None:
|
if solvable is not None:
|
||||||
lcur = conn.cursor()
|
lcur = conn.cursor()
|
||||||
lcur.execute("UPDATE seeds SET feasible = (%s) WHERE seed = (%s)", (solvable, seed))
|
lcur.execute("UPDATE seeds SET feasible = (%s) WHERE seed = (%s)", (solvable, seed))
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
if solvable == True:
|
if solvable == True:
|
||||||
with open("remaining_cards.txt", "a") as f:
|
with open("remaining_cards.txt", "a") as f:
|
||||||
f.write("Success with {} cards left in draw by greedy solver on seed {}: {}\n".format(num_remaining_cards, seed ,link(solution.to_json())))
|
f.write("Success with {} cards left in draw by greedy solver on seed {}: {}\n".format(num_remaining_cards, seed ,link(solution.to_json())))
|
||||||
elif solvable == False:
|
elif solvable == False:
|
||||||
logger.info("seed {} was not solvable".format(seed))
|
logger.info("seed {} was not solvable".format(seed))
|
||||||
with open('infeasible_instances.txt', 'a') as f:
|
with open('infeasible_instances.txt', 'a') as f:
|
||||||
f.write('{}-player, seed {:10}, {}\n'.format(num_players, seed, variant_name(var_id)))
|
f.write('{}-player, seed {:10}, {}\n'.format(num_players, seed, variant_name(var_id)))
|
||||||
elif solvable is None:
|
elif solvable is None:
|
||||||
logger.info("seed {} skipped".format(seed))
|
logger.info("seed {} skipped".format(seed))
|
||||||
else:
|
else:
|
||||||
raise Exception("Programming Error")
|
raise Exception("Programming Error")
|
||||||
|
|
||||||
mutex.release()
|
mutex.release()
|
||||||
|
except Exception:
|
||||||
|
traceback.format_exc()
|
||||||
|
print("exception in subprocess:")
|
||||||
|
|
||||||
|
|
||||||
def solve_unknown_seeds():
|
def solve_unknown_seeds():
|
||||||
|
|
|
@ -4,3 +4,4 @@ pysmt
|
||||||
termcolor
|
termcolor
|
||||||
more_itertools
|
more_itertools
|
||||||
psycopg2
|
psycopg2
|
||||||
|
alive_progress
|
||||||
|
|
Loading…
Reference in a new issue