[Numpy-discussion] Should ndarray be a context manager?

Nathaniel Smith njs at pobox.com
Wed Dec 10 18:34:49 EST 2014


On Wed, Dec 10, 2014 at 9:03 PM, Chris Barker <chris.barker at noaa.gov> wrote:
> On Wed, Dec 10, 2014 at 11:44 AM, Andrea Gavana <andrea.gavana at gmail.com>
> wrote:
>>
>> The argument is not check_refs, but refcheck.
>
> thanks -- yup, that works.
>
> Useful --  but dangerous!
>
> I haven't managed to trigger a segfault yet but it sure looks like I
> could...

On Linux at least this should work reliably:

In [1]: a = np.zeros(2 ** 20)

In [2]: b = a[...]

In [3]: a.resize((0,), refcheck=False)

In [4]: b[1000] = 1
zsh: segmentation fault  ipython

-n

-- 
Nathaniel J. Smith
Postdoctoral researcher - Informatics - University of Edinburgh
http://vorpus.org



More information about the NumPy-Discussion mailing list