Skip to content

Inherit and Extend apsw.cursor class #381

@kmedcalf

Description

@kmedcalf

I have modifiied my cursor wrapper so that it inherits from apsw.cursor and adds some extension slots (I also do the same thing with the apsw.connection class, as you know). Recently I noticed that when "closing" the connection (which calls super().close) that something was happening that was taking a huge amount of time.

Investigation found that although the cursor object(s) (in this case several hundred thousand or millions of them) all appeared to be closed and released properly, the apsw.Connection.close method was doing some sort of "loop though and close/free dependents".

I added the following to my apsw.Cursor extension which solved the problem (I previously had no close or __del__ methods (the close method is not called in the ordinary course, and having the __del__ call super().close (whether with or without force) seems to fix the issue.

+    def close(self, *args, **kwds):
+        self.__convert = None
+        self.__makerow = None
+        super().close(*args, **kwds)
+
+    # Needed to add this method to force the dependents to clean themselves up
+    def __del__(self):
+        self.__convert = None
+        self.__makerow = None
+        super().close(True)
+

FYI, the millions of cursors were all "INSERT" statements (the same statement with different bindings) that should have run to completion on the first step and were then discarded. Is this because I am extending using __slots__ rather than via a dict?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions