From: | Heikki Linnakangas <hlinnaka(at)iki(dot)fi> |
---|---|
To: | Mario De Frutos Dieguez <mariodefrutos(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: signal handling in plpython |
Date: | 2016-10-14 10:01:48 |
Message-ID: | e2c4c551-4afb-1f12-496a-aeb3faa3fbd0@iki.fi |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On 10/13/2016 08:57 PM, Mario De Frutos Dieguez wrote:
> I come here asking for some advice/help because we're facing some
> unexpected behavior when we want to interrupt functions doing CPU intensive
> operations in plpython.
>
> Our problem is that we're not able to interrupt them when they're making
> CPU intensive operations. For example, when calculating Moran using PySAL,
> the SIGINT handler of Postgres is not able to cancel it.
Python code isn't interruptible, but any queries you run within a python
function are. So if you have a loop in your function that you know will
run for a long time, you could issue a dummy "SELECT 1" query every once
in a while. However, that doesn't help, if the long loop is in a library
function that you have no control over, rather than the PL/python
function itself.
It would be nice to have a solution for this in plpython itself, so that
the query cancel was turned into a Python exception. Patches for that
would be welcome. I think you could use Py_AddPendingCall() from
PostgreSQL's signal handler, to schedule a call to a function that in
turn throws a Python exception. That'll need some changes to
PostgreSQL's normal signal handlers, like die() and
StatementCancelHandler() in postgres.c, but it seems doable.
- Heikki
From | Date | Subject | |
---|---|---|---|
Next Message | Shay Rojansky | 2016-10-14 10:09:44 | Re: PATCH: Batch/pipelining support for libpq |
Previous Message | Yury Zhuravlev | 2016-10-14 09:51:57 | Re: WIP: About CMake v2 |