bpo-25066: Added repr for multiprocessing.Event (GH-29749)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
This commit is contained in:
Kumar Aditya 2021-12-09 18:46:45 +05:30 committed by GitHub
parent e2cfc89e09
commit af6b406885
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 1 deletions

View File

@ -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
# #

View File

@ -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
# #

View File

@ -0,0 +1 @@
Added a :meth:`__repr__` method to :class:`multiprocessing.Event` objects, patch by Kumar Aditya.