Re: signal handling in plpython - Mailing list pgsql-hackers

From Tom Lane
Subject Re: signal handling in plpython
Date
Msg-id 4878.1476449107@sss.pgh.pa.us
Whole thread Raw
In response to Re: signal handling in plpython  (Heikki Linnakangas <hlinnaka@iki.fi>)
Responses Re: signal handling in plpython  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Heikki Linnakangas <hlinnaka@iki.fi> writes:
> 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.

Py_AddPendingCall is safe to call from a signal handler?  That would
be ... quite remarkable.  I should think it'd at least need to do a
malloc().  Also, seeing that it's documented as part of Python threading,
I wonder whether we can call it at all without the backend becoming
multithreaded.

> That'll need some changes to 
> PostgreSQL's normal signal handlers, like die() and 
> StatementCancelHandler() in postgres.c, but it seems doable.

I'm not in principle averse to letting extensions get control in
the signal handlers, but I'm afraid that any such feature would
mostly act as a magnet for unsafe coding.
        regards, tom lane



pgsql-hackers by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: Stats sender and 2pc minor problem
Next
From: Craig Ringer
Date:
Subject: Re: PATCH: Batch/pipelining support for libpq