summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKumar Aditya <rahuladitya303@gmail.com>2021-12-09 18:46:45 +0530
committerGitHub <noreply@github.com>2021-12-09 13:16:45 +0000
commitaf6b4068859a5d0c8afd696f3c0c0155660211a4 (patch)
tree51c7e19fc4f539e345c1464175af5abe7fbcd7e3
parente2cfc89e099b8fad5d8d5bd7f59dadffb6078778 (diff)
downloadcpython-git-af6b4068859a5d0c8afd696f3c0c0155660211a4.tar.gz
bpo-25066: Added repr for multiprocessing.Event (GH-29749)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
-rw-r--r--Lib/multiprocessing/synchronize.py3
-rw-r--r--Lib/test/_test_multiprocessing.py15
-rw-r--r--Misc/NEWS.d/next/Library/2021-11-24-12-25-42.bpo-25066.YIcIkn.rst1
3 files changed, 18 insertions, 1 deletions
diff --git a/Lib/multiprocessing/synchronize.py b/Lib/multiprocessing/synchronize.py
index d0be48f1fd..42624b5436 100644
--- a/Lib/multiprocessing/synchronize.py
+++ b/Lib/multiprocessing/synchronize.py
@@ -353,6 +353,9 @@ class Event(object):
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 3bc5b8f3d7..b2d656ab42 100644
--- a/Lib/test/_test_multiprocessing.py
+++ b/Lib/test/_test_multiprocessing.py
@@ -1645,7 +1645,20 @@ class _TestEvent(BaseTestCase):
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 0000000000..df19d04164
--- /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