Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
b46b9d59
Kaydet (Commit)
b46b9d59
authored
Agu 21, 2010
tarafından
Antoine Pitrou
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #9617: Signals received during a low-level write operation aren't
ignored by the buffered IO layer anymore.
üst
522180a6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
87 additions
and
1 deletion
+87
-1
test_io.py
Lib/test/test_io.py
+74
-1
NEWS
Misc/NEWS
+3
-0
bufferedio.c
Modules/_io/bufferedio.c
+10
-0
No files found.
Lib/test/test_io.py
Dosyayı görüntüle @
b46b9d59
...
...
@@ -27,6 +27,8 @@ import random
import
unittest
import
weakref
import
abc
import
signal
import
errno
from
itertools
import
cycle
,
count
from
collections
import
deque
from
test
import
support
...
...
@@ -2463,6 +2465,75 @@ class CMiscIOTest(MiscIOTest):
class
PyMiscIOTest
(
MiscIOTest
):
io
=
pyio
@unittest.skipIf
(
os
.
name
==
'nt'
,
'POSIX signals required for this test.'
)
class
SignalsTest
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
oldalrm
=
signal
.
signal
(
signal
.
SIGALRM
,
self
.
alarm_interrupt
)
def
tearDown
(
self
):
signal
.
signal
(
signal
.
SIGALRM
,
self
.
oldalrm
)
def
alarm_interrupt
(
self
,
sig
,
frame
):
1
/
0
@unittest.skipUnless
(
threading
,
'Threading required for this test.'
)
def
check_interrupted_write
(
self
,
item
,
bytes
,
**
fdopen_kwargs
):
"""Check that a partial write, when it gets interrupted, properly
invokes the signal handler."""
read_results
=
[]
def
_read
():
s
=
os
.
read
(
r
,
1
)
read_results
.
append
(
s
)
t
=
threading
.
Thread
(
target
=
_read
)
t
.
daemon
=
True
r
,
w
=
os
.
pipe
()
try
:
wio
=
self
.
io
.
open
(
w
,
**
fdopen_kwargs
)
t
.
start
()
signal
.
alarm
(
1
)
# Fill the pipe enough that the write will be blocking.
# It will be interrupted by the timer armed above. Since the
# other thread has read one byte, the low-level write will
# return with a successful (partial) result rather than an EINTR.
# The buffered IO layer must check for pending signal
# handlers, which in this case will invoke alarm_interrupt().
self
.
assertRaises
(
ZeroDivisionError
,
wio
.
write
,
item
*
(
1024
*
1024
))
t
.
join
()
# We got one byte, get another one and check that it isn't a
# repeat of the first one.
read_results
.
append
(
os
.
read
(
r
,
1
))
self
.
assertEqual
(
read_results
,
[
bytes
[
0
:
1
],
bytes
[
1
:
2
]])
finally
:
os
.
close
(
w
)
os
.
close
(
r
)
# This is deliberate. If we didn't close the file descriptor
# before closing wio, wio would try to flush its internal
# buffer, and block again.
try
:
wio
.
close
()
except
IOError
as
e
:
if
e
.
errno
!=
errno
.
EBADF
:
raise
def
test_interrupted_write_unbuffered
(
self
):
self
.
check_interrupted_write
(
b
"xy"
,
b
"xy"
,
mode
=
"wb"
,
buffering
=
0
)
def
test_interrupted_write_buffered
(
self
):
self
.
check_interrupted_write
(
b
"xy"
,
b
"xy"
,
mode
=
"wb"
)
def
test_interrupted_write_text
(
self
):
self
.
check_interrupted_write
(
"xy"
,
b
"xy"
,
mode
=
"w"
,
encoding
=
"ascii"
)
class
CSignalsTest
(
SignalsTest
):
io
=
io
class
PySignalsTest
(
SignalsTest
):
io
=
pyio
def
test_main
():
tests
=
(
CIOTest
,
PyIOTest
,
CBufferedReaderTest
,
PyBufferedReaderTest
,
...
...
@@ -2472,7 +2543,9 @@ def test_main():
StatefulIncrementalDecoderTest
,
CIncrementalNewlineDecoderTest
,
PyIncrementalNewlineDecoderTest
,
CTextIOWrapperTest
,
PyTextIOWrapperTest
,
CMiscIOTest
,
PyMiscIOTest
,)
CMiscIOTest
,
PyMiscIOTest
,
CSignalsTest
,
PySignalsTest
,
)
# Put the namespaces of the IO module we are testing and some useful mock
# classes in the __dict__ of each test.
...
...
Misc/NEWS
Dosyayı görüntüle @
b46b9d59
...
...
@@ -117,6 +117,9 @@ Extensions
Library
-------
- Issue #9617: Signals received during a low-level write operation aren't
ignored by the buffered IO layer anymore.
- Issue #843590: Make "macintosh" an alias to the "mac_roman" encoding.
- Create os.fsdecode(): decode from the filesystem encoding with
...
...
Modules/_io/bufferedio.c
Dosyayı görüntüle @
b46b9d59
...
...
@@ -1665,6 +1665,11 @@ _bufferedwriter_flush_unlocked(buffered *self, int restore_pos)
self
->
write_pos
+=
n
;
self
->
raw_pos
=
self
->
write_pos
;
written
+=
Py_SAFE_DOWNCAST
(
n
,
Py_off_t
,
Py_ssize_t
);
/* Partial writes can return successfully when interrupted by a
signal (see write(2)). We must run signal handlers before
blocking another time, possibly indefinitely. */
if
(
PyErr_CheckSignals
()
<
0
)
goto
error
;
}
if
(
restore_pos
)
{
...
...
@@ -1802,6 +1807,11 @@ bufferedwriter_write(buffered *self, PyObject *args)
}
written
+=
n
;
remaining
-=
n
;
/* Partial writes can return successfully when interrupted by a
signal (see write(2)). We must run signal handlers before
blocking another time, possibly indefinitely. */
if
(
PyErr_CheckSignals
()
<
0
)
goto
error
;
}
if
(
self
->
readable
)
_bufferedreader_reset_buf
(
self
);
...
...
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