Skip to content

Handle nonexistent or inaccessible startup cwd gracefully in wspbus - #2087

Open
DYNOSuprovo wants to merge 2 commits into
cherrypy:mainfrom
DYNOSuprovo:fix/graceful-nonexistent-cwd-2055
Open

DYNOSuprovo wants to merge 2 commits into
cherrypy:mainfrom
DYNOSuprovo:fix/graceful-nonexistent-cwd-2055

Conversation

@DYNOSuprovo

Copy link
Copy Markdown

Fixes #2055

Summary

When cherrypy is imported in an environment where the current working directory was removed or is inaccessible, wspbus.py crashed during module import because _startup_cwd = os.getcwd() was called unguarded at top level.

This change:

  1. Catches (FileNotFoundError, OSError) when initializing _startup_cwd at import time, falling back to None.
  2. Guards os.chdir(_startup_cwd) in _do_execv so that if _startup_cwd is None or raises (FileNotFoundError, OSError), it does not prevent process restart or crash.
  3. Adds tests in cherrypy/test/test_bus.py verifying that importing with a nonexistent working directory succeeds and that _do_execv handles _startup_cwd=None and inaccessible directories gracefully.

DYNOSuprovo and others added 2 commits September 29, 2026 13:26
Signed-off-by: DYNOSuprovo <DYNOSuprovo@users.noreply.github.com>
@read-the-docs-community

Copy link
Copy Markdown

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Uncaught exception using cherrypy/__init__.py from a non-existent dir.

1 participant