[dak/master 2/2] Replace DBConn.reset() by something more robust.
Signed-off-by: Torsten Werner <twerner@debian.org>
---
daklib/contents.py | 7 -------
daklib/dbconn.py | 14 +++++---------
tests/dbtest_multiproc.py | 5 +----
3 files changed, 6 insertions(+), 20 deletions(-)
diff --git a/daklib/contents.py b/daklib/contents.py
index b56a9c6..4a0b3ae 100755
--- a/daklib/contents.py
+++ b/daklib/contents.py
@@ -241,7 +241,6 @@ def generate_helper(suite_id, arch_id, overridetype_id, component_id = None):
'''
This function is called in a new subprocess.
'''
- DBConn().reset()
session = DBConn().session()
suite = Suite.get(suite_id, session)
architecture = Architecture.get(arch_id, session)
@@ -308,15 +307,9 @@ class ContentsScanner(object):
session.close()
return { 'processed': processed, 'remaining': remaining }
-reset = False
-
def scan_helper(binary_id):
'''
This function runs in a subprocess.
'''
- global reset
- if not reset:
- DBConn().reset()
- reset = True
scanner = ContentsScanner(binary_id)
scanner.scan()
diff --git a/daklib/dbconn.py b/daklib/dbconn.py
index 1968dd0..bf77b2a 100755
--- a/daklib/dbconn.py
+++ b/daklib/dbconn.py
@@ -3223,19 +3223,15 @@ class DBConn(object):
self.__setuptables()
self.__setupmappers()
+ self.pid = os.getpid()
def session(self):
+ # reinitialize DBConn in new processes
+ if self.pid != os.getpid():
+ clear_mappers()
+ self.__createconn()
return self.db_smaker()
- def reset(self):
- '''
- Resets the DBConn object. This function must be called by subprocesses
- created by the multiprocessing module. See tests/dbtest_multiproc.py
- for an example.
- '''
- clear_mappers()
- self.__createconn()
-
__all__.append('DBConn')
diff --git a/tests/dbtest_multiproc.py b/tests/dbtest_multiproc.py
index f4c2a37..0452020 100755
--- a/tests/dbtest_multiproc.py
+++ b/tests/dbtest_multiproc.py
@@ -9,7 +9,6 @@ from time import sleep
import unittest
def read_number():
- DBConn().reset()
session = DBConn().session()
result = session.query('foo').from_statement('select 7 as foo').scalar()
sleep(0.1)
@@ -18,9 +17,7 @@ def read_number():
class MultiProcTestCase(DBDakTestCase):
"""
- This TestCase checks that DBConn works with multiprocessing. A fresh
- subprocess needs to call reset() on DBConn(). See function read_number()
- for an example.
+ This TestCase checks that DBConn works with multiprocessing.
"""
def save_result(self, result):
--
1.7.2.5
Reply to: