Files
apache--tvm/python
Tianqi Chen dfe4cebbda [RUNTIME] Improve signal handling in python env. (#7919)
* [RUNTIME] Improve signal handling in python env.

Python execution environment handles the signal by caching
the signal a state and invokes the handler when execution
goes into the python interpreter.

This model can cause problem when runnning a long running
c++ function. As keyboard interrupt can only be caught in the end.

Additionally, because python registered special signal handlers.
Socket operations can return EINTR that needs to be explicitly
retried when the interrupt is not a KeyboardInterrupt.

This PR adds the following changes to resolve these problems.

- Allow execution env(python) to register CheckSignals function
  to the TVM runtime.
- Add runtime::EnvCheckSignals to check the signal error.
- Add retry when EINTR is encountered in socket.
- Register the python C API functions in cython mode.

To testout the EnvCheckSignals, run the following code

```python
import tvm.testing
tvm.testing.run_check_signal(10)
```

Note that the C API functions are only registered in cython FFI mode
because ctypes have problems invoking these functions. This however
won't affect the correctness, but will defer the interrupt handling
to function return sites.

Co-authored-by: Andrew Reusch <areusch@octoml.ai>
Co-authored-by: Robert Kimball <bobkimball@gmail.com>

* Address comments

* Alternative implementation that preserves python exception.

* Address comments

* Update check signals

Co-authored-by: Andrew Reusch <areusch@octoml.ai>
Co-authored-by: Robert Kimball <bobkimball@gmail.com>
2021-05-14 21:17:14 -04:00
..