Skip to content

Commit

Permalink
allocated: bugfix: remove __del__
Browse files Browse the repository at this point in the history
may cause python crash
  • Loading branch information
doronz88 committed Apr 1, 2022
1 parent 237f8ad commit be91b85
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 be91b85

Please sign in to comment.