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
78ed83da
Kaydet (Commit)
78ed83da
authored
Ara 19, 2011
tarafından
Charles-François Natali
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #11867: Make test_mailbox.test_lock_conflict deterministic (and fix a
race condition).
üst
62f3d030
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
9 deletions
+21
-9
test_mailbox.py
Lib/test/test_mailbox.py
+21
-9
No files found.
Lib/test/test_mailbox.py
Dosyayı görüntüle @
78ed83da
...
@@ -17,6 +17,10 @@ try:
...
@@ -17,6 +17,10 @@ try:
import
fcntl
import
fcntl
except
ImportError
:
except
ImportError
:
pass
pass
try
:
import
multiprocessing
except
ImportError
:
multiprocessing
=
None
class
TestBase
(
unittest
.
TestCase
):
class
TestBase
(
unittest
.
TestCase
):
...
@@ -994,28 +998,36 @@ class _TestMboxMMDF(TestMailbox):
...
@@ -994,28 +998,36 @@ class _TestMboxMMDF(TestMailbox):
self
.
assertEqual
(
contents
,
f
.
read
())
self
.
assertEqual
(
contents
,
f
.
read
())
self
.
_box
=
self
.
_factory
(
self
.
_path
)
self
.
_box
=
self
.
_factory
(
self
.
_path
)
@unittest.skipUnless
(
hasattr
(
os
,
'fork'
),
"Test needs fork()."
)
@unittest.skipUnless
(
multiprocessing
,
"Test needs multiprocessing."
)
def
test_lock_conflict
(
self
):
def
test_lock_conflict
(
self
):
# Fork off a subprocess that will lock the file for 2 seconds,
# Fork off a child process that will lock the mailbox temporarily,
# unlock it, and then exit.
# unlock it and exit.
if
not
hasattr
(
os
,
'fork'
):
ready
=
multiprocessing
.
Event
()
return
done
=
multiprocessing
.
Event
()
pid
=
os
.
fork
()
pid
=
os
.
fork
()
if
pid
==
0
:
if
pid
==
0
:
#
In the child, lock the mailbox.
#
child
try
:
try
:
# lock the mailbox, and signal the parent it can proceed
self
.
_box
.
lock
()
self
.
_box
.
lock
()
time
.
sleep
(
2
)
ready
.
set
()
# wait until the parent is done, and unlock the mailbox
done
.
wait
(
5
)
self
.
_box
.
unlock
()
self
.
_box
.
unlock
()
finally
:
finally
:
os
.
_exit
(
0
)
os
.
_exit
(
0
)
# In the parent, sleep a bit to give the child time to acquire
# In the parent, wait until the child signals it locked the mailbox.
# the lock.
ready
.
wait
(
5
)
time
.
sleep
(
0.5
)
try
:
try
:
self
.
assertRaises
(
mailbox
.
ExternalClashError
,
self
.
assertRaises
(
mailbox
.
ExternalClashError
,
self
.
_box
.
lock
)
self
.
_box
.
lock
)
finally
:
finally
:
# Signal the child it can now release the lock and exit.
done
.
set
()
# Wait for child to exit. Locking should now succeed.
# Wait for child to exit. Locking should now succeed.
exited_pid
,
status
=
os
.
waitpid
(
pid
,
0
)
exited_pid
,
status
=
os
.
waitpid
(
pid
,
0
)
...
...
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