Title: os.close(1) crashes REPL · Issue #6146 · RustPython/RustPython · GitHub
Open Graph Title: os.close(1) crashes REPL · Issue #6146 · RustPython/RustPython
X Title: os.close(1) crashes REPL · Issue #6146 · RustPython/RustPython
Description: Summary I was trying to work on #5521 and I noticed that in the repl if you try to os.close(sys.stdout.fileno()) or more concisely os.close(1) it crashes with a Readline error: Errno(EBADF) like this: omarabdelgawad@omarabdelgawad:~/my_w...
Open Graph Description: Summary I was trying to work on #5521 and I noticed that in the repl if you try to os.close(sys.stdout.fileno()) or more concisely os.close(1) it crashes with a Readline error: Errno(EBADF) like th...
X Description: Summary I was trying to work on #5521 and I noticed that in the repl if you try to os.close(sys.stdout.fileno()) or more concisely os.close(1) it crashes with a Readline error: Errno(EBADF) like th...
Opengraph URL: https://github.com/RustPython/RustPython/issues/6146
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"os.close(1) crashes REPL","articleBody":"## Summary\n\nI was trying to work on #5521 and I noticed that in the repl if you try to `os.close(sys.stdout.fileno())` or more concisely `os.close(1)` it crashes with a `Readline error: Errno(EBADF)` like this:\n```console\nomarabdelgawad@omarabdelgawad:~/my_workspace/RustPython$ cargo run --release \n Finished `release` profile [optimized] target(s) in 0.11s\n Running `target/release/rustpython`\nWelcome to the magnificent Rust Python 0.4.0 interpreter 😱 🖖\nRustPython 3.13.0\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n\u003e\u003e\u003e\u003e\u003e import os\n\u003e\u003e\u003e\u003e\u003e os.close(1)\nReadline error: Errno(EBADF)\nomarabdelgawad@omarabdelgawad:~/my_workspace/RustPython$\n```\n\n## Details\n\nwhere with CPython it doesnt crash:\n```console\nomarabdelgawad@omarabdelgawad:~$ python\nPython 3.12.3 (main, Aug 14 2025, 17:47:21) [GCC 13.3.0] on linux\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n\u003e\u003e\u003e import os\n\u003e\u003e\u003e os.close(1)\n\u003e\u003e\u003e x = 2\n\u003e\u003e\u003e print(x)\nTraceback (most recent call last):\n File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\nOSError: [Errno 9] Bad file descriptor\n\u003e\u003e\u003e ^C\nKeyboardInterrupt\n\u003e\u003e\u003e \nException ignored in: \u003c_io.TextIOWrapper name='\u003cstdout\u003e' mode='w' encoding='utf-8'\u003e\nOSError: [Errno 9] Bad file descriptor\nomarabdelgawad@omarabdelgawad:~$ \n```\nI also noticed that even with `-c \"script\"` it kind of silently crashes:\n```console\nomarabdelgawad@omarabdelgawad:~/my_workspace/RustPython$ cargo run --release -q -- -c \"import os; os.close(1);print('hello')\"\nomarabdelgawad@omarabdelgawad:~/my_workspace/RustPython$ \n```\nwhile CPython has the same behaviour:\n```console\nomarabdelgawad@omarabdelgawad:~/my_workspace/projects/github_repos/RustPython$ python -c \"import os; os.close(1);print('hello')\"\nTraceback (most recent call last):\n File \"\u003cstring\u003e\", line 1, in \u003cmodule\u003e\nOSError: [Errno 9] Bad file descriptor\nException ignored in: \u003c_io.TextIOWrapper name='\u003cstdout\u003e' mode='w' encoding='utf-8'\u003e\nOSError: [Errno 9] Bad file descriptor\n```\n","author":{"url":"https://github.com/omar-abdelgawad","@type":"Person","name":"omar-abdelgawad"},"datePublished":"2025-09-12T20:30:45.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/6146/RustPython/issues/6146"}
| 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:7ad7a483-f663-2272-8e4f-20c10f863d4d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EB20:CD10D:11AEF54:16DC92A:696B1318 |
| html-safe-nonce | 04d0045049f9a9a59c2ae8c67575d306ea86061d82272357dda92ead210722d9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQjIwOkNEMTBEOjExQUVGNTQ6MTZEQzkyQTo2OTZCMTMxOCIsInZpc2l0b3JfaWQiOiIxNTUxMDQ1MjYwODE0NzgzMjU3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 53c9546d1cdee6575f3261d24dc3cd628c33b54f7af58b475e37209b0464200c |
| hovercard-subject-tag | issue:3411862863 |
| 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/RustPython/RustPython/6146/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a3a900b50be01e6d032fb06e6d69069c5d604700e3ab7ea2ef3b9d6658830b5f/RustPython/RustPython/issues/6146 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a3a900b50be01e6d032fb06e6d69069c5d604700e3ab7ea2ef3b9d6658830b5f/RustPython/RustPython/issues/6146 |
| og:image:alt | Summary I was trying to work on #5521 and I noticed that in the repl if you try to os.close(sys.stdout.fileno()) or more concisely os.close(1) it crashes with a Readline error: Errno(EBADF) like th... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | omar-abdelgawad |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5f99f7c1d70f01da5b93e5ca90303359738944d8ab470e396496262c66e60b8d |
| turbo-cache-control | no-preview |
| go-import | github.com/RustPython/RustPython git https://github.com/RustPython/RustPython.git |
| octolytics-dimension-user_id | 39710557 |
| octolytics-dimension-user_login | RustPython |
| octolytics-dimension-repository_id | 135201145 |
| octolytics-dimension-repository_nwo | RustPython/RustPython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 135201145 |
| octolytics-dimension-repository_network_root_nwo | RustPython/RustPython |
| 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 | 82560a55c6b2054555076f46e683151ee28a19bc |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width