summaryrefslogtreecommitdiffstats
path: root/Python/ceval.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2003-06-28 21:53:52 (GMT)
committerGuido van Rossum <guido@python.org>2003-06-28 21:53:52 (GMT)
commitb8b6d0c2c63bcd9252ce20ef990da093dda8b8ce (patch)
tree6a7d86081fd3a1be1d446f9b060133b5f340f614 /Python/ceval.c
parent90a2041ffd9789c19344bcf0d1b1e65138312736 (diff)
downloadcpython-b8b6d0c2c63bcd9252ce20ef990da093dda8b8ce.zip
cpython-b8b6d0c2c63bcd9252ce20ef990da093dda8b8ce.tar.gz
cpython-b8b6d0c2c63bcd9252ce20ef990da093dda8b8ce.tar.bz2
Add PyThreadState_SetAsyncExc(long, PyObject *).
A new API (only accessible from C) to interrupt a thread by sending it an exception. This is not always effective, but might help some people. Requested by Just van Rossum and Alex Martelli. It is intentional that you have to write your own C extension to call it from Python. Docs will have to wait.
Diffstat (limited to 'Python/ceval.c')
-rw-r--r--Python/ceval.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index 4e5b472..07862d0 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -290,7 +290,7 @@ static PyTypeObject gentype = {
extern int _PyThread_Started; /* Flag for Py_Exit */
-static PyThread_type_lock interpreter_lock = 0;
+static PyThread_type_lock interpreter_lock = 0; /* This is the GIL */
static long main_thread = 0;
void
@@ -773,6 +773,11 @@ eval_frame(PyFrameObject *f)
Py_MakePendingCalls() above. */
if (--_Py_Ticker < 0) {
+ if (*next_instr == SETUP_FINALLY) {
+ /* Make the last opcode before
+ a try: finally: block uninterruptable. */
+ goto fast_next_opcode;
+ }
_Py_Ticker = _Py_CheckInterval;
tstate->tick_counter++;
if (things_to_do) {
@@ -805,6 +810,17 @@ eval_frame(PyFrameObject *f)
PyThread_acquire_lock(interpreter_lock, 1);
if (PyThreadState_Swap(tstate) != NULL)
Py_FatalError("ceval: orphan tstate");
+
+ /* Check for thread interrupts */
+
+ if (tstate->async_exc != NULL) {
+ x = tstate->async_exc;
+ tstate->async_exc = NULL;
+ PyErr_SetNone(x);
+ Py_DECREF(x);
+ why = WHY_EXCEPTION;
+ goto on_error;
+ }
}
#endif
}