mirror of https://github.com/python/cpython
bpo-25066: Added repr for multiprocessing.Event (GH-29749)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
This commit is contained in:
parent
e2cfc89e09
commit
af6b406885
|
@ -353,6 +353,9 @@ class Event(object):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def __repr__(self) -> str:
|
||||||
|
set_status = 'set' if self.is_set() else 'unset'
|
||||||
|
return f"<{type(self).__qualname__} at {id(self):#x} {set_status}>"
|
||||||
#
|
#
|
||||||
# Barrier
|
# Barrier
|
||||||
#
|
#
|
||||||
|
|
|
@ -1645,7 +1645,20 @@ class _TestEvent(BaseTestCase):
|
||||||
self.assertEqual(wait(), True)
|
self.assertEqual(wait(), True)
|
||||||
p.join()
|
p.join()
|
||||||
|
|
||||||
#
|
def test_repr(self) -> None:
|
||||||
|
event = self.Event()
|
||||||
|
if self.TYPE == 'processes':
|
||||||
|
self.assertRegex(repr(event), r"<Event at .* unset>")
|
||||||
|
event.set()
|
||||||
|
self.assertRegex(repr(event), r"<Event at .* set>")
|
||||||
|
event.clear()
|
||||||
|
self.assertRegex(repr(event), r"<Event at .* unset>")
|
||||||
|
elif self.TYPE == 'manager':
|
||||||
|
self.assertRegex(repr(event), r"<EventProxy object, typeid 'Event' at .*")
|
||||||
|
event.set()
|
||||||
|
self.assertRegex(repr(event), r"<EventProxy object, typeid 'Event' at .*")
|
||||||
|
|
||||||
|
|
||||||
# Tests for Barrier - adapted from tests in test/lock_tests.py
|
# Tests for Barrier - adapted from tests in test/lock_tests.py
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Added a :meth:`__repr__` method to :class:`multiprocessing.Event` objects, patch by Kumar Aditya.
|
Loading…
Reference in New Issue