Re: signal handling in plpython

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
Cc: 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 12:45:07
Message-ID: 4878.1476449107@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Heikki Linnakangas <hlinnaka(at)iki(dot)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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Craig Ringer 2016-10-14 12:53:34 Re: PATCH: Batch/pipelining support for libpq
Previous Message Alvaro Herrera 2016-10-14 12:41:33 Re: Stats sender and 2pc minor problem