Title: bpo-43785 removed the lock from BZ2File, but on PyPy writing from multiple threads now deadlocks · Issue #100996 · python/cpython · GitHub
Open Graph Title: bpo-43785 removed the lock from BZ2File, but on PyPy writing from multiple threads now deadlocks · Issue #100996 · python/cpython
X Title: bpo-43785 removed the lock from BZ2File, but on PyPy writing from multiple threads now deadlocks · Issue #100996 · python/cpython
Description: Bug report A clear and concise description of what the bug is. Include a minimal, reproducible example (https://stackoverflow.com/help/minimal-reproducible-example), if possible. We are working on upgrading PyPy to stdlib v3.10.6. As par...
Open Graph Description: Bug report A clear and concise description of what the bug is. Include a minimal, reproducible example (https://stackoverflow.com/help/minimal-reproducible-example), if possible. We are working on ...
X Description: Bug report A clear and concise description of what the bug is. Include a minimal, reproducible example (https://stackoverflow.com/help/minimal-reproducible-example), if possible. We are working on ...
Opengraph URL: https://github.com/python/cpython/issues/100996
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"bpo-43785 removed the lock from BZ2File, but on PyPy writing from multiple threads now deadlocks","articleBody":"\u003c!--\r\n If you're new to Python and you're not sure whether what you're experiencing is a bug, the CPython issue tracker is not\r\n the right place to seek help. Consider the following options instead:\r\n\r\n - reading the Python tutorial: https://docs.python.org/3/tutorial/\r\n - posting in the \"Users\" category on discuss.python.org: https://discuss.python.org/c/users/7\r\n - emailing the Python-list mailing list: https://mail.python.org/mailman/listinfo/python-list\r\n - searching our issue tracker (https://github.com/python/cpython/issues) to see if\r\n your problem has already been reported\r\n-->\r\n\r\n# Bug report\r\n\r\nA clear and concise description of what the bug is.\r\nInclude a minimal, reproducible example (https://stackoverflow.com/help/minimal-reproducible-example), if possible.\r\n\r\nWe are working on upgrading PyPy to stdlib v3.10.6. As part of that work, we merge the contents of `Lib/*` to a py3.10 branch of PyPy and run the tests. We are seeing deadlocks in the `Lib/test/test_bz2.py` tests, specifically in the [testThreading](https://github.com/python/cpython/blob/eecd422d1ba849f0724962666ba840581217812b/Lib/test/test_bz2.py#L500) test. I can confirm that restoring the lock removed in #25299 (but only the part when writing to `self.fp`) breaks the deadlock:\r\n\r\n```diff\r\n--- a/lib-python/3/bz2.py Thu Jan 12 16:22:35 2023 +0200\r\n+++ b/lib-python/3/bz2.py Thu Jan 12 20:27:36 2023 +0200\r\n@@ -13,6 +13,7 @@\r\n import io\r\n import os\r\n import _compression\r\n+from threading import RLock\r\n \r\n from _bz2 import BZ2Compressor, BZ2Decompressor\r\n \r\n@@ -52,6 +53,9 @@\r\n If mode is 'r', the input file may be the concatenation of\r\n multiple compressed streams.\r\n \"\"\"\r\n+ # This lock must be recursive, so that BufferedIOBase's\r\n+ # writelines() does not deadlock.\r\n+ self._lock = RLock()\r\n self._fp = None\r\n self._closefp = False\r\n self._mode = _MODE_CLOSED\r\n@@ -227,9 +231,10 @@\r\n data = memoryview(data)\r\n length = data.nbytes\r\n \r\n- compressed = self._compressor.compress(data)\r\n- self._fp.write(compressed)\r\n- self._pos += length\r\n+ with self._lock:\r\n+ compressed = self._compressor.compress(data)\r\n+ self._fp.write(compressed)\r\n+ self._pos += length\r\n return length\r\n \r\n def writelines(self, seq):\r\n```\r\n\r\n# Your environment\r\nPyPy on the py3.10 branch, on Ubuntu 20.04.\r\n\r\nDoes CPython have a different locking mechanism for writing to a file to prevent this?\r\n\r\nxref @methane. I think the intention of the original issue was to improve reading speed, I don't see anything in the comments about writing.","author":{"url":"https://github.com/mattip","@type":"Person","name":"mattip"},"datePublished":"2023-01-12T18:32:38Z","url":"https://github.com/python/cpython/issues/100996"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:08b0714f-687f-f031-2458-44e471fe8605 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A390:1BD25B:CC7F36:1191039:6B00B495 |
| html-safe-nonce | b48e9d3c8ce55b3c41fbba6f8dfff8f60dbe87cbcd89b022566822a205d38f12 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMzkwOjFCRDI1QjpDQzdGMzY6MTE5MTAzOTo2QjAwQjQ5NSIsInZpc2l0b3JfaWQiOiI4MDg0Mjk3OTQ2NjkyMTA1MzY1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 6d8d552105862723708d8f6931d90ea7eac210759eb32c78bcef9898e41c0124 |
| hovercard-subject-tag | issue:1531182838 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/100996/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c242151b01c4c2ab2d8221bde891be42f89fbbad151ac3c0d0d779c54d66baeb/python/cpython/issues/100996 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c242151b01c4c2ab2d8221bde891be42f89fbbad151ac3c0d0d779c54d66baeb/python/cpython/issues/100996 |
| og:image:alt | Bug report A clear and concise description of what the bug is. Include a minimal, reproducible example (https://stackoverflow.com/help/minimal-reproducible-example), if possible. We are working on ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mattip |
| hostname | github.com |
| expected-hostname | github.com |
| None | 1d07c25977adfc5ff6acb0a962a9bc168c07afbda6fef765f9761c350c2ae4a2 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 5429cbfc6aca8c7b9a086a3c8f47400346f38cc9 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width