Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
db564238
Commit
db564238
authored
Sep 04, 2017
by
Neil Schemenauer
Committed by
GitHub
Sep 04, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "bpo-17852: Maintain a list of BufferedWriter objects. Flush them on exit. (#1908)" (#3337)
This reverts commit
e38d12ed
.
parent
e38d12ed
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
1 addition
and
75 deletions
+1
-75
Lib/_pyio.py
Lib/_pyio.py
+0
-24
Misc/NEWS.d/next/Core and Builtins/2017-09-04-12-46-25.bpo-17852.OxAtCg.rst
...ore and Builtins/2017-09-04-12-46-25.bpo-17852.OxAtCg.rst
+0
-2
Modules/_io/_iomodule.c
Modules/_io/_iomodule.c
+0
-2
Modules/_io/_iomodule.h
Modules/_io/_iomodule.h
+0
-2
Modules/_io/bufferedio.c
Modules/_io/bufferedio.c
+1
-45
No files found.
Lib/_pyio.py
View file @
db564238
...
...
@@ -1185,7 +1185,6 @@ class BufferedWriter(_BufferedIOMixin):
self
.
buffer_size
=
buffer_size
self
.
_write_buf
=
bytearray
()
self
.
_write_lock
=
Lock
()
_register_writer
(
self
)
def
writable
(
self
):
return
self
.
raw
.
writable
()
...
...
@@ -2575,26 +2574,3 @@ class StringIO(TextIOWrapper):
def
detach
(
self
):
# This doesn't make sense on StringIO.
self
.
_unsupported
(
"detach"
)
# ____________________________________________________________
import
atexit
,
weakref
_all_writers
=
weakref
.
WeakSet
()
def
_register_writer
(
w
):
# keep weak-ref to buffered writer
_all_writers
.
add
(
w
)
def
_flush_all_writers
():
# Ensure all buffered writers are flushed before proceeding with
# normal shutdown. Otherwise, if the underlying file objects get
# finalized before the buffered writer wrapping it then any buffered
# data will be lost.
for
w
in
_all_writers
:
try
:
w
.
flush
()
except
:
pass
atexit
.
register
(
_flush_all_writers
)
Misc/NEWS.d/next/Core and Builtins/2017-09-04-12-46-25.bpo-17852.OxAtCg.rst
deleted
100644 → 0
View file @
e38d12ed
Maintain a list of open buffered files, flush them before exiting the
interpreter. Based on a patch from Armin Rigo.
Modules/_io/_iomodule.c
View file @
db564238
...
...
@@ -766,8 +766,6 @@ PyInit__io(void)
!
(
_PyIO_empty_bytes
=
PyBytes_FromStringAndSize
(
NULL
,
0
)))
goto
fail
;
_Py_PyAtExit
(
_PyIO_atexit_flush
);
state
->
initialized
=
1
;
return
m
;
...
...
Modules/_io/_iomodule.h
View file @
db564238
...
...
@@ -183,5 +183,3 @@ extern PyObject *_PyIO_empty_str;
extern
PyObject
*
_PyIO_empty_bytes
;
extern
PyTypeObject
_PyBytesIOBuffer_Type
;
extern
void
_PyIO_atexit_flush
(
void
);
Modules/_io/bufferedio.c
View file @
db564238
...
...
@@ -196,7 +196,7 @@ bufferediobase_write(PyObject *self, PyObject *args)
}
typedef
struct
_buffered
{
typedef
struct
{
PyObject_HEAD
PyObject
*
raw
;
...
...
@@ -240,18 +240,8 @@ typedef struct _buffered {
PyObject
*
dict
;
PyObject
*
weakreflist
;
/* a doubly-linked chained list of "buffered" objects that need to
be flushed when the process exits */
struct
_buffered
*
next
,
*
prev
;
}
buffered
;
/* the actual list of buffered objects */
static
buffered
buffer_list_end
=
{
.
next
=
&
buffer_list_end
,
.
prev
=
&
buffer_list_end
};
/*
Implementation notes:
...
...
@@ -396,15 +386,6 @@ _enter_buffered_busy(buffered *self)
(self->buffer_size * (size / self->buffer_size)))
static
void
remove_from_linked_list
(
buffered
*
self
)
{
self
->
next
->
prev
=
self
->
prev
;
self
->
prev
->
next
=
self
->
next
;
self
->
prev
=
NULL
;
self
->
next
=
NULL
;
}
static
void
buffered_dealloc
(
buffered
*
self
)
{
...
...
@@ -413,8 +394,6 @@ buffered_dealloc(buffered *self)
return
;
_PyObject_GC_UNTRACK
(
self
);
self
->
ok
=
0
;
if
(
self
->
next
!=
NULL
)
remove_from_linked_list
(
self
);
if
(
self
->
weakreflist
!=
NULL
)
PyObject_ClearWeakRefs
((
PyObject
*
)
self
);
Py_CLEAR
(
self
->
raw
);
...
...
@@ -1838,33 +1817,10 @@ _io_BufferedWriter___init___impl(buffered *self, PyObject *raw,
self
->
fast_closed_checks
=
(
Py_TYPE
(
self
)
==
&
PyBufferedWriter_Type
&&
Py_TYPE
(
raw
)
==
&
PyFileIO_Type
);
if
(
self
->
next
==
NULL
)
{
self
->
prev
=
&
buffer_list_end
;
self
->
next
=
buffer_list_end
.
next
;
buffer_list_end
.
next
->
prev
=
self
;
buffer_list_end
.
next
=
self
;
}
self
->
ok
=
1
;
return
0
;
}
/*
* Ensure all buffered writers are flushed before proceeding with
* normal shutdown. Otherwise, if the underlying file objects get
* finalized before the buffered writer wrapping it then any buffered
* data will be lost.
*/
void
_PyIO_atexit_flush
(
void
)
{
while
(
buffer_list_end
.
next
!=
&
buffer_list_end
)
{
buffered
*
buf
=
buffer_list_end
.
next
;
remove_from_linked_list
(
buf
);
buffered_flush
(
buf
,
NULL
);
PyErr_Clear
();
}
}
static
Py_ssize_t
_bufferedwriter_raw_write
(
buffered
*
self
,
char
*
start
,
Py_ssize_t
len
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment