Skip to content
Permalink
Browse files
bpo-25066: Added repr for multiprocessing.Event (GH-29749)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
  • Loading branch information
kumaraditya303 and pablogsal committed Dec 9, 2021
1 parent e2cfc89 commit af6b4068859a5d0c8afd696f3c0c0155660211a4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
@@ -353,6 +353,9 @@ def wait(self, timeout=None):
return True
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
#
@@ -1645,7 +1645,20 @@ def test_event(self):
self.assertEqual(wait(), True)
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
#

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

0 comments on commit af6b406

Please sign in to comment.