Skip to content

Commit 7f7e154

Browse files
authored
Remove DBOS atexit Handler (#410)
The atexit handler prints warning messages if DBOS global instances do not exist, then calls `DBOS.destroy()`. Removing it because it is unintuitive and can often lead to spurious warnings. Calling `DBOS.destroy()` at shutdown is not necessary for safety.
1 parent 027beb8 commit 7f7e154

File tree

2 files changed

+0
-52
lines changed

2 files changed

+0
-52
lines changed

dbos/_dbos.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,31 +1376,3 @@ class DBOSConfiguredInstance:
13761376
def __init__(self, config_name: str) -> None:
13771377
self.config_name = config_name
13781378
DBOS.register_instance(self)
1379-
1380-
1381-
# Apps that import DBOS probably don't exit. If they do, let's see if
1382-
# it looks like startup was abandoned or a call was forgotten...
1383-
def _dbos_exit_hook() -> None:
1384-
if _dbos_global_registry is None:
1385-
# Probably used as or for a support module
1386-
return
1387-
if _dbos_global_instance is None:
1388-
print("DBOS exiting; functions were registered but DBOS() was not called")
1389-
dbos_logger.warning(
1390-
"DBOS exiting; functions were registered but DBOS() was not called"
1391-
)
1392-
return
1393-
if not _dbos_global_instance._launched:
1394-
if _dbos_global_instance.fastapi is not None:
1395-
# FastAPI lifespan middleware will call launch/destroy, so we can ignore this.
1396-
# This is likely to happen during fastapi dev runs, where the reloader loads the module multiple times.
1397-
return
1398-
print("DBOS exiting; DBOS exists but launch() was not called")
1399-
dbos_logger.warning("DBOS exiting; DBOS exists but launch() was not called")
1400-
return
1401-
# If we get here, we're exiting normally
1402-
_dbos_global_instance.destroy()
1403-
1404-
1405-
# Register the exit hook
1406-
atexit.register(_dbos_exit_hook)

tests/test_singleton.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -129,27 +129,3 @@ def test_dbos_singleton_negative(cleanup_test_databases: None) -> None:
129129
assert "launch" in str(exc_info.value)
130130

131131
DBOS.destroy()
132-
133-
134-
def test_dbos_atexit_no_dbos(cleanup_test_databases: None) -> None:
135-
# Run the .py as a separate process
136-
result = subprocess.run(
137-
[sys.executable, path.join("tests", "atexit_no_ctor.py")],
138-
capture_output=True,
139-
text=True,
140-
)
141-
142-
# Assert that the output contains the warning message
143-
assert "DBOS exiting; functions were registered" in result.stdout
144-
145-
146-
def test_dbos_atexit_no_launch(cleanup_test_databases: None) -> None:
147-
# Run the .py as a separate process
148-
result = subprocess.run(
149-
[sys.executable, path.join("tests", "atexit_no_launch.py")],
150-
capture_output=True,
151-
text=True,
152-
)
153-
154-
# Assert that the output contains the warning message
155-
assert "DBOS exists but launch() was not called" in result.stdout

0 commit comments

Comments
 (0)