Re: Does plpython support threading?

From: Jinhua Luo <luajit(dot)io(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Does plpython support threading?
Date: 2016-02-08 04:51:17
Message-ID: CAAc9rOw7d3j_YLq85EZ4zj1=KWPts5mjuzWnhf6Hy4EJNC8Zaw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

The new thread do not call any pg API or access any pg specific data.
The pg backend (main thread) puts string message into the python
Queue, and the new thread gets from the Queue and write to file, it's
simple and clear logic.

I test the same codes standalone, it works, but when I move them into
the plpython function. The new thread would be pause and seems freeze
(as said above, I even try to put a dead loop in the thread, it
doesn't run a dead loop actually).

So I guess it's somehow plpython specific limit?

Regards,
Jinhua Luo

2016-02-08 0:45 GMT+08:00 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:
> Jinhua Luo <luajit(dot)io(at)gmail(dot)com> writes:
>> In my plpython function, I create new thread to do some routine works.
>> But I found the thread doesn't work, it would run a while, but
>> suddenly pause and stop working. For example, I write a test dead loop
>> to print something to file, but it would stop printing after some
>> time.
>
>> I am wondering whether plpython supports threading or not.
>
> Creating multiple threads inside a Postgres backend is playing with fire.
> You can make it work if you're very very careful, but what's more likely
> to happen is you get burned. None of the backend code is multithread
> safe, so you must absolutely ensure that control never gets out of
> libpython except in the main thread.
>
> regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2016-02-08 05:08:55 Re: WAL Re-Writes
Previous Message Fujii Masao 2016-02-08 03:22:38 Re: GIN pending list clean up exposure to SQL