Skip to content

Commit

Permalink
Merge pull request #126 from doronz88/bugfix/allocated_del
Browse files Browse the repository at this point in the history
allocated: bugfix: remove `__del__`
  • Loading branch information
doronz88 authored Apr 1, 2022
2 parents 31fccde + be91b85 commit 653d35d
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 29 deletions.
6 changes: 0 additions & 6 deletions src/rpcclient/rpcclient/allocated.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ def __enter__(self):
def __exit__(self, exc_type, exc_val, exc_tb):
self.deallocate()

def __del__(self):
try:
self.deallocate()
except Exception:
pass

@abstractmethod
def _deallocate(self):
pass
Expand Down
23 changes: 0 additions & 23 deletions src/rpcclient/tests/test_allocation_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,6 @@ def test_allocate_file_fd_context_manager(client, tmp_path):
assert fds_count == len(client.processes.get_by_pid(client.pid).fds)


def test_allocate_file_fd_gc(client, tmp_path):
# make sure when the test starts, all previous Allocated references are freed
gc.collect()
fds_count = len(client.processes.get_by_pid(client.pid).fds)

# create a new fd with zero references, so it should be free immediately
client.fs.open(tmp_path / 'test', 'w')

# make sure python's GC had a chance to free the newly created fd
gc.collect()
assert fds_count == len(client.processes.get_by_pid(client.pid).fds)


def test_allocate_file_fd_explicit_del(client, tmp_path):
# make sure when the test starts, all previous Allocated references are freed
gc.collect()
fds_count = len(client.processes.get_by_pid(client.pid).fds)
fd = client.fs.open(tmp_path / 'test', 'w')
assert fds_count + 1 == len(client.processes.get_by_pid(client.pid).fds)
del fd
assert fds_count == len(client.processes.get_by_pid(client.pid).fds)


def test_allocate_file_fd_explicit_deallocate(client, tmp_path):
# make sure when the test starts, all previous Allocated references are freed
gc.collect()
Expand Down

0 comments on commit 653d35d

Please sign in to comment.