plasmodic/ecto — pull request #250 by stonier (2014-07-10 16:57:41+00:00)
Title: Experimental signal connection for sync executions.

This is experimental and just to initiate discussion (not specifically targeted for merging).

**Problem**

Commit dd8fef0ec00cbb9e489aa9156206e4f0508ac12c introduce a big change in the scheduler - multithreading was dropped and async support modified. In the process, signal handling got [disconnected](https://github.com/plasmodic/ecto/commit/dd8fef0ec00cbb9e489aa9156206e4f0508ac12c#diff-8102ff9c980072a684d1f6fbc7b01e57R185) (note the `#if 0`).

This means that the python ectoscript controlling this c++ execution would only receive a notification of the signal (via [PyErr_SetInterrupt()](https://github.com/plasmodic/ecto/blob/master/src/lib/scheduler.cpp#L61) only after any c++ execution terminated.

In the case of an `execute()` call, or `execute(niter=_some_large_number)`. This can be a very long time.

**Solutions**

You can force the python ecto script to check for signals with `PyErr_CheckSignals()`, see [Ethan's comment](https://github.com/plasmodic/ecto/blob/master/src/lib/scheduler.cpp#L65) but this may be a bad way of doing it. Perhaps it clobbers the underlying c++ execution? Better would be to get the c++ execution to terminate gracefully.

All I've done here is set a flag that replicates the `ecto::QUIT` behaviour. Another way would be to trigger it via `stop()` but I'm unclear on who or what calls that yet. It has issues trying that with the current code as well.