8000 BUG: disable garbage collector during memory allocation hook by juliantaylor · Pull Request #4841 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUG: disable garbage collector during memory allocation hook #4841

New issue 8000

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 5, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions tools/allocation_tracking/track_allocations.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import division, absolute_import, print_function

import numpy as np
import gc
import inspect
from alloc_hook import NumpyAllocHook

Expand Down Expand Up @@ -35,12 +36,21 @@ def __exit__(self, type, value, traceback):
self.numpy_hook.__exit__()

def hook(self, inptr, outptr, size):
# minimize the chances that the garbage collector kicks in during a
# cython __dealloc__ call and causes a double delete of the current
# object. To avoid this fully the hook would have to avoid all python
# api calls, e.g. by being implemented in C like python 3.4's
# tracemalloc module
gc_on = gc.isenabled()
gc.disable()
if outptr == 0: # it's a free
self.free_cb(inptr)
elif inptr != 0: # realloc
self.realloc_cb(inptr, outptr, size)
else: # malloc
self.alloc_cb(outptr, size)
if gc_on:
gc.enable()

def alloc_cb(self, ptr, size):
if size >= self.threshold:
Expand Down
0