From: Torsten Werner Date: Tue, 22 Mar 2011 20:05:58 +0000 (+0000) Subject: Replace DBConn.reset() by something more robust. X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;ds=sidebyside;h=bb6f8377370565ddf40541d68341c1d357acfc0f;p=dak.git Replace DBConn.reset() by something more robust. Signed-off-by: Torsten Werner --- diff --git a/daklib/contents.py b/daklib/contents.py index b56a9c6c..4a0b3ae2 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 1968dd0c..bf77b2a7 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 f4c2a37a..04520208 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):