Closed izgzhen closed 4 years ago
Hey! Can I work on this? Can I know where file this is being produced from?
@punndcoder28 Sure, I've added more detailed and assigned it to you. Thanks!
Unfortunately, this issue may not be easy to solve. Cozy uses the Z3 library directly, rather than invoking Z3 as an external process. The Z3 library API offers timeouts, but as far as I know it does not offer a way to interrupt a running call. Since Cozy uses Python multiprocessing you might try to kill the multiprocessing jobs, but that also won't work: killing a multiprocess job can corrupt the communication channels between the main process and the multiprocessing job, resulting in unexpected crashes.
I believe that this issue is still worth working on, since it is a huge annoyance when it happens. I hope that I have missed some easy solution.
OK. If I run into any problems I will leave a comment here. Thanks.
since it is a huge annoyance when it happens
My experience is that it will happen 50% of all time...and when it does happen and I can't wait, I simply send interrupt from Ctrl-C and kill it off. So, I think the most essential thing is to save the work on disk (as specified in --save
) before killing everything off after receiving an interrupt signal from the users. In this vein, we can try to add an interrupt handler and let it access the best solution state so far. It doesn't matter if we need to use terminate API and corrupt the queue, as long as we don't corrupt the existing solution in memory.
To summarize: my recommendation is to save the work when interrupted by user/timer and brutally exit ASAP.
Modern versions of Z3 catch SIGINT: https://github.com/Z3Prover/z3/blob/d75ce380169617379fb9dff40ed6ff62b1955dc0/src/util/scoped_ctrl_c.cpp#L47
A SIGINT signal causes Z3 to return "unknown", as it would do for a timeout.
Here's my proposal for resolving this issue:
Job.request_stop
) and then sends a SIGINT to the worker process.In the original example, it appears the job is actually busy converting the syntax tree into a Z3 query, so additionally:
(And perhaps we should look into optimizing encoding bag equality a little...)
Currently, Cozy will hang at the following state for a long time:
I guess Cozy is waiting for Z3 to return -- but this might far exceed the specified timeout (10s).
We should be able to let Cozy give up early, kill the Z3 job and output immediately after timeout.
NOTE: some hints on the semantic of
timeout
https://github.com/CozySynthesizer/cozy/issues/52