Using psycopg2 / gevent / psycogreen: handling aborts

Поиск
Список
Период
Сортировка
От Robert Lerche (rlerche)
Тема Using psycopg2 / gevent / psycogreen: handling aborts
Дата
Msg-id eec2b297a42746c5bffedd85e7a9d6a7@XCH-RTP-002.cisco.com
обсуждение исходный текст
Список psycopg

Hi.  I have a problem to report.  Let me explain the scenario.

 

Cisco acquired Truviso in 2012, and I joined Cisco as part of the acquisition.  Truviso created a streaming engine based on PostgreSQL, adding the streaming functionality as first-class objects in the database.  Cisco now ships this product as “Connected Streaming Analytics.”

 

The way results are produced is a push style, different from the usual database approach of pulling data via a query.  Instead a client consuming results creates a special “window” cursor (specifying the stream via a select) and loops doing FETCH.  The FETCH blocks until a window closes and produces data.  The client consumes the data and returns to the top of the loop to wait for more data.

 

I’m writing an example program that handles multiple streams, so it needs to camp on multiple connections.  I was glad to find the green thread implementation because it is just the thing to implement this scheme.

 

However, I also want to handle termination via a Ctrl-C or a SIGTERM.  The client has to cancel the connections so the PostgreSQL back-end processes will terminate properly.  conn.cancel() works and if I only do that everything goes away.    BUT, if I try to conn.close() or conn.rollback() in the cancel() path, the client hangs.

 

I was able to reproduce the symptom using just a “select pg_sleep()” … without a final conn.close() the program terminates and so do the backend processes. Or if I just let the program terminate without Ctrl-C it terminates smoothly. If I put a close() or a rollback() the client program (attached) hangs.  [I based this on your test_gevent.py example.]

 

Thanks for any help you can give me and thanks also for all this good work!

 

 

Вложения

В списке psycopg по дате отправления:

Предыдущее
От: "P. Christeas"
Дата:
Сообщение: Re: Psycopg2 GSSAPI
Следующее
От: Levente
Дата:
Сообщение: install on windows