[issue21363] io.TextIOWrapper always closes wrapped files

2021-06-03 Thread Marten H. van Kerkwijk


Marten H. van Kerkwijk  added the comment:

In astropy we are now working around the auto-closing of the underlying stream 
in TextIOWrapper by subclassing and overriding `__del__` to detach [1]. It 
would seem more elegant if `TestIOWrapper` (and really, `BufferedReader`) could 
gain an `closefd` argument, just like `open` has, which is `True` by default.

p.s. Do let me know if it is better to open a new issue.

[1] https://github.com/astropy/astropy/pull/11809

--
nosy: +mhvk
type:  -> enhancement

___
Python tracker 
<https://bugs.python.org/issue21363>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40720] accessing mmap of file that is overwritten causes bus error

2020-05-22 Thread Marten H. van Kerkwijk


Marten H. van Kerkwijk  added the comment:

I should probably have added that the bus error happens on linux. On Windows, 
the opening of the file for writing leads to an error, as the file is still 
opened for reading inside the mmap.

--

___
Python tracker 
<https://bugs.python.org/issue40720>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40720] accessing mmap of file that is overwritten causes bus error

2020-05-21 Thread Marten H. van Kerkwijk


New submission from Marten H. van Kerkwijk :

While debugging a strange failure with tests and np.memmap, I realized that the 
following direct use of mmap reliably leads to a bus error. Here, obviously 
mmap'ing a file, closing it, opening the file for writing but not writing 
anything, and then again accessing the mmap is not something one should do (but 
a test case did it anyway), but it would nevertheless be nice to avoid a crash!
```
import mmap


with open('test.dat', 'wb') as fh:
fh.write(b'abcdefghijklmnopqrstuvwxyz')


with open('test.dat', 'rb') as fh:
mm = mmap.mmap(fh.fileno(), 0, access=mmap.ACCESS_READ)


with open('test.dat', 'wb') as fh:
pass  # Note: if something is written, then I get no bus error.


mm[2]
```

--
components: Library (Lib)
messages: 369543
nosy: mhvk
priority: normal
severity: normal
status: open
title: accessing mmap of file that is overwritten causes bus error
type: crash
versions: Python 3.8

___
Python tracker 
<https://bugs.python.org/issue40720>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com