Skip to content

Commit 8450dd1

Browse files
authored
Replace sys.stderr.write() with print(file=sys.stderr) (#1131)
1 parent 6b844e8 commit 8450dd1

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
* Fixed `input_task_button` not working in a Shiny module. (#1108)
1414
* Fixed several issues with `page_navbar()` styling. (#1124)
1515

16+
### Other changes
17+
18+
* Replaced use of `sys.stderr.write()` with `print(file=sys.stderr)`, because on some platforms `sys.stderr` can be `None`. (#1131)
19+
20+
1621
## [0.7.1] - 2024-02-05
1722

1823
### Bug fixes

shiny/_main.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,9 @@ def run_app(
314314
autoreload_port = _utils.random_port(host=host)
315315

316316
if autoreload_port == port:
317-
sys.stderr.write(
318-
"Autoreload port is already being used by the app; disabling autoreload\n"
317+
print(
318+
"Autoreload port is already being used by the app; disabling autoreload\n",
319+
file=sys.stderr,
319320
)
320321
reload = False
321322
else:
@@ -426,10 +427,10 @@ def resolve_app(app: str, app_dir: str | None) -> tuple[str, str | None]:
426427
# unfriendly. We should probably throw a custom error that the shiny run
427428
# entrypoint knows not to print the stack trace for.
428429
if not os.path.exists(module_path):
429-
sys.stderr.write(f"Error: {module_path} not found\n")
430+
print(f"Error: {module_path} not found\n", file=sys.stderr)
430431
sys.exit(1)
431432
if not os.path.isfile(module_path):
432-
sys.stderr.write(f"Error: {module_path} is not a file\n")
433+
print(f"Error: {module_path} is not a file\n", file=sys.stderr)
433434
sys.exit(1)
434435
dirname, filename = os.path.split(module_path)
435436
module = filename[:-3] if filename.endswith(".py") else filename

tests/pytest/asyncio_prevent.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ def new_event_loop(self):
3333

3434
# Doing this instead of "import shiny" so no linter is tempted to remove it
3535
importlib.import_module("shiny")
36-
sys.stderr.write(
36+
print(
3737
"Success; shiny module loading did not attempt to access an asyncio event "
38-
"loop\n"
38+
"loop\n",
39+
file=sys.stderr,
3940
)

0 commit comments

Comments
 (0)