Title: [Example 20-8][demo_executor_map.py] Race condition bug in display function · Issue #68 · fluentpython/example-code-2e · GitHub
Open Graph Title: [Example 20-8][demo_executor_map.py] Race condition bug in display function · Issue #68 · fluentpython/example-code-2e
X Title: [Example 20-8][demo_executor_map.py] Race condition bug in display function · Issue #68 · fluentpython/example-code-2e
Description: On my machine, threads switch between the two print() calls in the display function, causing output from different calls to interleave. For example, I get multiple timestamps on the same line or mixed output from different loiter() calls...
Open Graph Description: On my machine, threads switch between the two print() calls in the display function, causing output from different calls to interleave. For example, I get multiple timestamps on the same line or mi...
X Description: On my machine, threads switch between the two print() calls in the display function, causing output from different calls to interleave. For example, I get multiple timestamps on the same line or mi...
Opengraph URL: https://github.com/fluentpython/example-code-2e/issues/68
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Example 20-8][demo_executor_map.py] Race condition bug in display function","articleBody":"On my machine, threads switch between the two `print()` calls in the `display`\nfunction, causing output from different calls to interleave. For example, I get \nmultiple timestamps on the same line or mixed output from different `loiter()`\ncalls.\n\n```bash\n[22:43:48] Script starting.\n[22:43:48] loiter(0): doing nothing for 0s...\n[22:43:48] [22:43:48] \tloiter(1): doing nothing for 1s...loiter(0): done.\n\n[22:43:48] \t\tloiter(2): doing nothing for 2s...\n[22:43:48][22:43:48] \t\t\tloiter(3): doing nothing for 3s... \nresults: \u003cgenerator object Executor.map.\u003clocals>.result_iterator at 0x000001E48D7C3CD0>\n```\n\nI tried combining the output into a single print() call, but the issue still\nappears because print() with multiple arguments performs multiple writes to\nstdout.\n\nThe solution I found was to use a lock.\n\n```python\nfrom threading import Lock\n\nlock = Lock()\n\ndef display(*args):\n with lock:\n print(strftime('[%H:%M:%S]'), end=' ')\n print(*args)\n```","author":{"url":"https://github.com/Kristiyan-Ivanov","@type":"Person","name":"Kristiyan-Ivanov"},"datePublished":"2026-05-02T19:59:43Z","url":"https://github.com/fluentpython/example-code-2e/issues/68"}
| 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:82996e79-7350-1ab5-c004-f7fca37f2720 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 826E:23E430:1923264:211A860:6B067707 |
| html-safe-nonce | 9d787a75b5d7f16f96231485bb4f3ef19a5fca3ddd84c9cb5ea67a45d71ebb29 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MjZFOjIzRTQzMDoxOTIzMjY0OjIxMUE4NjA6NkIwNjc3MDciLCJ2aXNpdG9yX2lkIjoiMTgyOTAyNTEzMDYwNTg2ODgwNyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 195ff930d62caf286393f5b7412842c23138cdcc3eeaecb01e0c85c1de77375f |
| hovercard-subject-tag | issue:4369880340 |
| 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/fluentpython/example-code-2e/68/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3f2cd65a1a79546e884a937ef54f7f85c65e5a9e349857b4f812b62e15145558/fluentpython/example-code-2e/issues/68 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3f2cd65a1a79546e884a937ef54f7f85c65e5a9e349857b4f812b62e15145558/fluentpython/example-code-2e/issues/68 |
| og:image:alt | On my machine, threads switch between the two print() calls in the display function, causing output from different calls to interleave. For example, I get multiple timestamps on the same line or mi... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Kristiyan-Ivanov |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4462ff7ebfd3d551f202659f2423dae617b6849d23b1df6465dc504ef497d14a |
| turbo-cache-control | no-preview |
| go-import | github.com/fluentpython/example-code-2e git https://github.com/fluentpython/example-code-2e.git |
| octolytics-dimension-user_id | 9216311 |
| octolytics-dimension-user_login | fluentpython |
| octolytics-dimension-repository_id | 176997413 |
| octolytics-dimension-repository_nwo | fluentpython/example-code-2e |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 176997413 |
| octolytics-dimension-repository_network_root_nwo | fluentpython/example-code-2e |
| 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 | 6d3909414814ff86ce7da4c51a0f4918a13fb41b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width