"" :
try:
finally:
hander.__exit__()
, handler (, ). , , " -", .
- __exit__, with . , BacktestingDatabaseHelper, with.
, , with try ... finally , __exit__ . , ( , , BacktestingDatabaseHelper),
try:
handler = self.db
finally:
handler.close()
Edit : Since you cannot change it, you should do something like @Daniel Roseman suggests a wrap BacktestingDatabaseHelper. Depending on how best to clean BacktestingDatabaseHelper(as stated above), you might write something like:
from contextlib import contextmanager
@contextmanager
def closing(thing):
try:
yield thing
finally:
thing.close()
and use it like:
class mfReportProcess(testingResource):
def __init__(self):
self.db = closing(BacktestingDatabaseHelper.fromConfig('db_name'))
(this is directly from the documentation ).
source
share