Skip to content

Commit 0bd5df9

Browse files
Add low-level access to fb_shutdown_callback API functions
libfbclient handle signals on its own, so driver will get shutdown error on SIGTERM/SIGINT/SIGBREAK and there is no other possibilities to prevent it and softly stop process except handling shutdown manually: Example of fb_shutdown_callback usage: @FB_SHUTDOWN_CALLBACK def driver_shutdown_callback(reason, mask, arg): return 1 if reason == fb_shutrsn_signal else 0 def api_loaded_hook(api): status = ISC_STATUS_ARRAY(20) api.fb_shutdown_callback(status, driver_shutdown_callback, fb_shut_confirmation, None) if db_api_error(status): raise exception_from_status(InternalError, status, "Error while adding shutdown callback") add_hook(APIHook.LOADED, FirebirdAPI, api_loaded_hook)
1 parent ee0c566 commit 0bd5df9

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

firebird/driver/fbapi.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,22 @@
123123
blr_ex_time_tz = 30
124124
blr_ex_timestamp_tz = 31
125125

126+
# Masks for fb_shutdown_callback
127+
fb_shut_confirmation = 1
128+
fb_shut_preproviders = 2
129+
fb_shut_postproviders = 4
130+
fb_shut_finish = 8
131+
fb_shut_exit = 16
132+
133+
# Shutdown reasons, used by engine
134+
fb_shutrsn_svc_stopped = -1
135+
fb_shutrsn_no_connection = -2
136+
fb_shutrsn_app_stopped = -3
137+
fb_shutrsn_signal = -5
138+
fb_shutrsn_services = -6
139+
fb_shutrsn_exit_called = -7
140+
fb_shutrsn_emergency = -8
141+
126142
if platform.architecture() == ('64bit', 'WindowsPE'): # pragma: no cover
127143
intptr_t = c_longlong
128144
uintptr_t = c_ulonglong
@@ -238,6 +254,7 @@ class ISC_QUAD(Structure):
238254

239255
RESULT_VECTOR = ISC_ULONG * 15
240256
ISC_EVENT_CALLBACK = CFUNCTYPE(None, POINTER(ISC_UCHAR), c_ushort, POINTER(ISC_UCHAR))
257+
FB_SHUTDOWN_CALLBACK = CFUNCTYPE(c_int, c_int, c_int, c_void_p)
241258

242259
# >>> Firebird 4
243260
class ISC_TIME_TZ(Structure):
@@ -1951,6 +1968,13 @@ def __init__(self, filename: Path = None):
19511968
self.fb_sqlstate.restype = None
19521969
self.fb_sqlstate.argtypes = [STRING, ISC_STATUS_PTR]
19531970
#
1971+
self.fb_shutdown_callback = self.client_library.fb_shutdown_callback
1972+
self.fb_shutdown_callback.restype = ISC_STATUS
1973+
self.fb_shutdown_callback.argtypes = [ISC_STATUS_PTR,
1974+
FB_SHUTDOWN_CALLBACK,
1975+
c_int,
1976+
c_void_p]
1977+
#
19541978
self.isc_sqlcode = self.client_library.isc_sqlcode
19551979
self.isc_sqlcode.restype = ISC_LONG
19561980
self.isc_sqlcode.argtypes = [ISC_STATUS_PTR]

0 commit comments

Comments
 (0)