Title: Example Dockerfile should document to run python unbuffered · Issue #604 · docker-library/python · GitHub
Open Graph Title: Example Dockerfile should document to run python unbuffered · Issue #604 · docker-library/python
X Title: Example Dockerfile should document to run python unbuffered · Issue #604 · docker-library/python
Description: The example Dockerfile in the Create a Dockerfile in your python App Project section in the image documentation should have ENV PYTHONUNBUFFERED=1 or add the -u option to CMD [ "python", "-u", "./your-daemon-or-script.py" ] From https://...
Open Graph Description: The example Dockerfile in the Create a Dockerfile in your python App Project section in the image documentation should have ENV PYTHONUNBUFFERED=1 or add the -u option to CMD [ "python", "-u", "./y...
X Description: The example Dockerfile in the Create a Dockerfile in your python App Project section in the image documentation should have ENV PYTHONUNBUFFERED=1 or add the -u option to CMD [ "python", ...
Opengraph URL: https://github.com/docker-library/python/issues/604
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Example Dockerfile should document to run python unbuffered","articleBody":"The example Dockerfile in the [Create a Dockerfile in your python App Project](https://github.com/docker-library/docs/blob/master/python/content.md#create-a-dockerfile-in-your-python-app-project) section in the image documentation should have\r\n\r\n```Dockerfile\r\nENV PYTHONUNBUFFERED=1\r\n```\r\nor add the `-u` option to \r\n```Dockerfile\r\nCMD [ \"python\", \"-u\", \"./your-daemon-or-script.py\" ]\r\n```\r\n\r\nFrom https://docs.python.org/3/library/sys.html#sys.stdout:\r\n\r\n> When interactive, the `stdout` stream is line-buffered. Otherwise, it is block-buffered like regular text files. The `stderr` stream is line-buffered in both cases. You can make both streams unbuffered by passing the `-u` command-line option or setting the `PYTHONUNBUFFERED` environment variable.\r\n**Changed in version 3.9: Non-interactive stderr is now line-buffered instead of fully buffered.**\r\n\r\nWhen running a container non-interactively, no output from the python script or daemon are flushed to `stdout` until the block buffer is full (generally `DEFAULT_BUFFER_SIZE = 8192`) or the container terminates. For daemons which do not terminate and which may not have much logging over its lifetime, nothing may be logged at all. \r\n\r\nThis makes viewing / tailing the container logs in realtime which by default captures stdout problematic, especially when viewing the logs in conjunction with other services.\r\n\r\nExample `docker-compose.yaml` which demonstrates this issue.\r\n\r\n```yaml\r\n---\r\nservices:\r\n demo:\r\n image: python:3\r\n command:\r\n - python\r\n - -c\r\n - |\r\n import time\r\n for i in range(10):\r\n print(i)\r\n time.sleep(1)\r\n```\r\nNo output is written until the container terminates.\r\n\r\nIt took me a while to figure out what the problem was, believing it was a problem with Docker not flushing logs to the driver (with `--log-opt mode=non-blocking`) or getting blocked (with `--log-opt mode=blocking` - the default), until I realised it was a problem specific to Python. Adding changes to the Python image documentation would help users with similar problems. E.g. https://github.com/moby/moby/issues/12447#issuecomment-94416623 and https://stackoverflow.com/questions/29663459/python-app-does-not-print-anything-when-running-detached-in-docker\r\n\r\nThe Docker Python Guide docs, https://docs.docker.com/language/python/build-images/ should also be updated.","author":{"url":"https://github.com/tmoschou","@type":"Person","name":"tmoschou"},"datePublished":"2021-04-17T03:40:19Z","url":"https://github.com/docker-library/python/issues/604"}
| 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:c3456b0d-8c56-68ac-f266-470540c6378b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8916:22BB81:CC5CBA:10C2E4F:6AFE8B70 |
| html-safe-nonce | fb6dbf9247368ca1e0034c4a10e9c3046ec5c0af0a0a3f310616c0ea397322d4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4OTE2OjIyQkI4MTpDQzVDQkE6MTBDMkU0Rjo2QUZFOEI3MCIsInZpc2l0b3JfaWQiOiI3Mjk2ODUzMDExOTQxMTk4NzA0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 620d6231ba41d10a64ff71f835da4378494402c52fc1e280836bc945fc1e0e60 |
| hovercard-subject-tag | issue:860314217 |
| 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/docker-library/python/604/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2694b9617b55f75e18266d6ae549f913218c05cacbd8c31fb05eb0021ffeb1f6/docker-library/python/issues/604 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2694b9617b55f75e18266d6ae549f913218c05cacbd8c31fb05eb0021ffeb1f6/docker-library/python/issues/604 |
| og:image:alt | The example Dockerfile in the Create a Dockerfile in your python App Project section in the image documentation should have ENV PYTHONUNBUFFERED=1 or add the -u option to CMD [ "python", "-u", "./y... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | tmoschou |
| hostname | github.com |
| expected-hostname | github.com |
| None | b3c0f155eafc27e60db6e254d1ffff0e072e9ab3b4018a5ee518797c19d89f86 |
| turbo-cache-control | no-preview |
| go-import | github.com/docker-library/python git https://github.com/docker-library/python.git |
| octolytics-dimension-user_id | 7739233 |
| octolytics-dimension-user_login | docker-library |
| octolytics-dimension-repository_id | 21054928 |
| octolytics-dimension-repository_nwo | docker-library/python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 21054928 |
| octolytics-dimension-repository_network_root_nwo | docker-library/python |
| 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 | 4a10310af51a1bfffbedc4fd81cb582acf0cb0ff |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width