Skip to content

Commit dd54ab6

Browse files
committed
Check if python interpreter is still initialized.
Try to avoid executing our callback if the python interpreter is not initialized. Callbacks can occur after python has been finalized; trying to access the GIL in this case causes undefined behavior.
1 parent 69cce37 commit dd54ab6

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

bindings/python/src/AsyncResponseHandler.hh

+10
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ namespace PyXRootD
5757
XrdCl::AnyObject *response,
5858
XrdCl::HostList *hostList )
5959
{
60+
// If we get called while the program's exit handlers are being called,
61+
// then calls to PyGILState_Ensure() deadlock. Py_IsInitialized() is
62+
// not thread-safe but we appear to be lacking in alternates.
63+
if (!Py_IsInitialized()) {return;}
64+
6065
//----------------------------------------------------------------------
6166
// Ensure we hold the Global Interpreter Lock
6267
//----------------------------------------------------------------------
@@ -164,6 +169,11 @@ namespace PyXRootD
164169
void HandleResponse( XrdCl::XRootDStatus *status,
165170
XrdCl::AnyObject *response )
166171
{
172+
// If we get called while the program's exit handlers are being called,
173+
// then calls to PyGILState_Ensure() deadlock. Py_IsInitialized() is
174+
// not thread-safe but we appear to be lacking in alternates.
175+
if (!Py_IsInitialized()) {return;}
176+
167177
//----------------------------------------------------------------------
168178
// Ensure we hold the Global Interpreter Lock
169179
//----------------------------------------------------------------------

0 commit comments

Comments
 (0)