From 7c5afd6977c2d71a1a3f9550849580b75851a65b Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Sun, 17 Mar 2019 23:06:55 +0000 Subject: [PATCH] Added test to reproduce ticket #829 Unrelated processes close the FD of the connection. This happens in Python 3.6 but not 2.7. Let's see if travis shows where else it fails... --- tests/test_connection.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/test_connection.py b/tests/test_connection.py index 77f3b29d..75abcc02 100755 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -357,6 +357,34 @@ class ConnectionTests(ConnectingTestCase): conn.close() self.assert_(conn.pgconn_ptr is None) + @slow + def test_multiprocess_close(self): + script = ("""\ +import time +import threading +import multiprocessing +import psycopg2 + +def thread(): + conn = psycopg2.connect(%(dsn)r) + curs = conn.cursor() + for i in range(10): + curs.execute("select 1") + time.sleep(0.1) + +def process(): + time.sleep(0.2) + +t = threading.Thread(target=thread, name='mythread') +t.start() +time.sleep(0.2) +multiprocessing.Process(target=process, name='myprocess').start() +t.join() +""" % {'dsn': dsn}) + + out = sp.check_output([sys.executable, '-c', script], stderr=sp.STDOUT) + self.assertEqual(out, b'', out.decode('ascii')) + class ParseDsnTestCase(ConnectingTestCase): def test_parse_dsn(self):