Signed-off-by: Torsten Werner <twerner@debian.org>
'''
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)
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()
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')
import unittest
def read_number():
- DBConn().reset()
session = DBConn().session()
result = session.query('foo').from_statement('select 7 as foo').scalar()
sleep(0.1)
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):