[Python-checkins] bpo-25066: Added repr for multiprocessing.Event (GH-29749)
pablogsal
webhook-mailer at python.org
Thu Dec 9 08:16:50 EST 2021
https://github.com/python/cpython/commit/af6b4068859a5d0c8afd696f3c0c0155660211a4
commit: af6b4068859a5d0c8afd696f3c0c0155660211a4
branch: main
author: Kumar Aditya <rahuladitya303 at gmail.com>
committer: pablogsal <Pablogsal at gmail.com>
date: 2021-12-09T13:16:45Z
summary:
bpo-25066: Added repr for multiprocessing.Event (GH-29749)
Co-authored-by: Pablo Galindo Salgado <Pablogsal at gmail.com>
files:
A Misc/NEWS.d/next/Library/2021-11-24-12-25-42.bpo-25066.YIcIkn.rst
M Lib/multiprocessing/synchronize.py
M Lib/test/_test_multiprocessing.py
diff --git a/Lib/multiprocessing/synchronize.py b/Lib/multiprocessing/synchronize.py
index d0be48f1fd7a8..42624b543601a 100644
--- a/Lib/multiprocessing/synchronize.py
+++ b/Lib/multiprocessing/synchronize.py
@@ -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
#
diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py
index 3bc5b8f3d79b0..b2d656ab42897 100644
--- a/Lib/test/_test_multiprocessing.py
+++ b/Lib/test/_test_multiprocessing.py
@@ -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
#
diff --git a/Misc/NEWS.d/next/Library/2021-11-24-12-25-42.bpo-25066.YIcIkn.rst b/Misc/NEWS.d/next/Library/2021-11-24-12-25-42.bpo-25066.YIcIkn.rst
new file mode 100644
index 0000000000000..df19d041644c2
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2021-11-24-12-25-42.bpo-25066.YIcIkn.rst
@@ -0,0 +1 @@
+Added a :meth:`__repr__` method to :class:`multiprocessing.Event` objects, patch by Kumar Aditya.
\ No newline at end of file
More information about the Python-checkins
mailing list