From 134d0951b0fc8ecf213eda9b9715d3cd4ed4abf1 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Fri, 20 Sep 2013 23:18:03 -0700 Subject: [PATCH] Remove weakref usage If a connection escapes the scope of the backend object, then python will actually garbage collect the backend object even though the connection object has a property that allows you to fetch the backend. If the property is used after the gc occurs a weakref failure occurs. Python is smart enough to correctly deallocate these types of object links by itself so lets just let it do that. Fixes: bug 1228968 Change-Id: I49d36b74f896bd1be6c7a1a373b07bdaded3ef4b --- taskflow/persistence/backends/impl_memory.py | 3 +-- taskflow/persistence/backends/impl_sqlalchemy.py | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/taskflow/persistence/backends/impl_memory.py b/taskflow/persistence/backends/impl_memory.py index 9ba041ad..49ccbf86 100644 --- a/taskflow/persistence/backends/impl_memory.py +++ b/taskflow/persistence/backends/impl_memory.py @@ -22,7 +22,6 @@ import copy import logging import threading -import weakref from taskflow import decorators from taskflow import exceptions as exc @@ -63,7 +62,7 @@ class Connection(base.Connection): def __init__(self, backend): self._read_lock = _READ_LOCK self._save_locks = _READ_SAVE_ORDER - self._backend = weakref.proxy(backend) + self._backend = backend def upgrade(self): pass diff --git a/taskflow/persistence/backends/impl_sqlalchemy.py b/taskflow/persistence/backends/impl_sqlalchemy.py index 1456cbf5..83a98c90 100644 --- a/taskflow/persistence/backends/impl_sqlalchemy.py +++ b/taskflow/persistence/backends/impl_sqlalchemy.py @@ -25,7 +25,6 @@ import contextlib import copy import logging import time -import weakref import sqlalchemy as sa from sqlalchemy import exceptions as sa_exc @@ -260,7 +259,7 @@ class SQLAlchemyBackend(base.Backend): class Connection(base.Connection): def __init__(self, backend, session_maker): - self._backend = weakref.proxy(backend) + self._backend = backend self._session_maker = session_maker self._engine = backend.engine