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
5e193ac0
Kaydet (Commit)
5e193ac0
authored
Eyl 24, 2014
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #22427: TemporaryDirectory no longer attempts to clean up twice when
used in the with statement in generator.
üst
b87630c2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
12 deletions
+30
-12
tempfile.py
Lib/tempfile.py
+3
-12
test_tempfile.py
Lib/test/test_tempfile.py
+24
-0
NEWS
Misc/NEWS
+3
-0
No files found.
Lib/tempfile.py
Dosyayı görüntüle @
5e193ac0
...
...
@@ -663,11 +663,6 @@ class TemporaryDirectory(object):
in it are removed.
"""
# Handle mkdtemp raising an exception
name
=
None
_finalizer
=
None
_closed
=
False
def
__init__
(
self
,
suffix
=
""
,
prefix
=
template
,
dir
=
None
):
self
.
name
=
mkdtemp
(
suffix
,
prefix
,
dir
)
self
.
_finalizer
=
_weakref
.
finalize
(
...
...
@@ -675,10 +670,9 @@ class TemporaryDirectory(object):
warn_message
=
"Implicitly cleaning up {!r}"
.
format
(
self
))
@classmethod
def
_cleanup
(
cls
,
name
,
warn_message
=
None
):
def
_cleanup
(
cls
,
name
,
warn_message
):
_shutil
.
rmtree
(
name
)
if
warn_message
is
not
None
:
_warnings
.
warn
(
warn_message
,
ResourceWarning
)
_warnings
.
warn
(
warn_message
,
ResourceWarning
)
def
__repr__
(
self
):
...
...
@@ -691,8 +685,5 @@ class TemporaryDirectory(object):
self
.
cleanup
()
def
cleanup
(
self
):
if
self
.
_finalizer
is
not
None
:
self
.
_finalizer
.
detach
()
if
self
.
name
is
not
None
and
not
self
.
_closed
:
if
self
.
_finalizer
.
detach
():
_shutil
.
rmtree
(
self
.
name
)
self
.
_closed
=
True
Lib/test/test_tempfile.py
Dosyayı görüntüle @
5e193ac0
...
...
@@ -1211,6 +1211,30 @@ class TestTemporaryDirectory(BaseTestCase):
self
.
assertNotIn
(
"Exception "
,
err
)
self
.
assertIn
(
"ResourceWarning: Implicitly cleaning up"
,
err
)
def
test_exit_on_shutdown
(
self
):
# Issue #22427
with
self
.
do_create
()
as
dir
:
code
=
"""if True:
import sys
import tempfile
import warnings
def generator():
with tempfile.TemporaryDirectory(dir={dir!r}) as tmp:
yield tmp
g = generator()
sys.stdout.buffer.write(next(g).encode())
warnings.filterwarnings("always", category=ResourceWarning)
"""
.
format
(
dir
=
dir
)
rc
,
out
,
err
=
script_helper
.
assert_python_ok
(
"-c"
,
code
)
tmp_name
=
out
.
decode
()
.
strip
()
self
.
assertFalse
(
os
.
path
.
exists
(
tmp_name
),
"TemporaryDirectory
%
s exists after cleanup"
%
tmp_name
)
err
=
err
.
decode
(
'utf-8'
,
'backslashreplace'
)
self
.
assertNotIn
(
"Exception "
,
err
)
self
.
assertIn
(
"ResourceWarning: Implicitly cleaning up"
,
err
)
def
test_warnings_on_cleanup
(
self
):
# ResourceWarning will be triggered by __del__
with
self
.
do_create
()
as
dir
:
...
...
Misc/NEWS
Dosyayı görüntüle @
5e193ac0
...
...
@@ -13,6 +13,9 @@ Core and Builtins
Library
-------
- Issue #22427: TemporaryDirectory no longer attempts to clean up twice when
used in the with statement in generator.
- Issue #20912: Now directories added to ZIP file have correct Unix and MS-DOS
directory attributes.
...
...
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