Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Python] Ensure Python module doesn't deadlock/segv on exit, fixes #330
- Loading branch information
1 parent
00b69a1
commit 912673b
Showing
4 changed files
with
91 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#------------------------------------------------------------------------------- | ||
# Copyright (c) 2012-2014 by European Organization for Nuclear Research (CERN) | ||
# Author: Michal Simon <michal.simon@cern.ch> | ||
#------------------------------------------------------------------------------- | ||
# This file is part of the XRootD software suite. | ||
# | ||
# XRootD is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Lesser General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# XRootD is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Lesser General Public License | ||
# along with XRootD. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
# In applying this licence, CERN does not waive the privileges and immunities | ||
# granted to it by virtue of its status as an Intergovernmental Organization | ||
# or submit itself to any jurisdiction. | ||
#------------------------------------------------------------------------------ | ||
|
||
import atexit | ||
from pyxrootd import client | ||
|
||
@atexit.register | ||
def finalize(): | ||
"""Python atexit handler, will stop all XRootD client threads | ||
(XrdCl JobManager, TaskManager and Poller) in order to ensure | ||
no Python APIs are called after the Python Interpreter gets | ||
finalized. | ||
""" | ||
client.__XrdCl_Stop_Threads() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
//------------------------------------------------------------------------------ | ||
// Copyright (c) 2012-2013 by European Organization for Nuclear Research (CERN) | ||
// Author: Michal Simon <michal.simon@cern.ch> | ||
//------------------------------------------------------------------------------ | ||
// This file is part of the XRootD software suite. | ||
// | ||
// XRootD is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// XRootD is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with XRootD. If not, see <http://www.gnu.org/licenses/>. | ||
// | ||
// In applying this licence, CERN does not waive the privileges and immunities | ||
// granted to it by virtue of its status as an Intergovernmental Organization | ||
// or submit itself to any jurisdiction. | ||
//------------------------------------------------------------------------------ | ||
#ifndef BINDINGS_PYTHON_SRC_PYXROOTDFINALIZE_HH_ | ||
#define BINDINGS_PYTHON_SRC_PYXROOTDFINALIZE_HH_ | ||
|
||
#include "PyXRootD.hh" | ||
|
||
#include "XrdCl/XrdClDefaultEnv.hh" | ||
#include "XrdCl/XrdClPostMaster.hh" | ||
|
||
namespace PyXRootD | ||
{ | ||
|
||
//---------------------------------------------------------------------------- | ||
//! Waits until XrdCl JobManager, TaskManager and Poller will stop gracefully. | ||
//! | ||
//! To be used in Python native atexit handler in order to make sure there are | ||
//! no outstanding threads after the Python interpreter got finalized. | ||
//---------------------------------------------------------------------------- | ||
PyObject* __XrdCl_Stop_Threads( PyObject *self, PyObject* ) | ||
{ | ||
Py_BEGIN_ALLOW_THREADS | ||
XrdCl::DefaultEnv::GetPostMaster()->Stop(); | ||
Py_END_ALLOW_THREADS | ||
Py_RETURN_NONE; | ||
} | ||
} | ||
|
||
#endif /* BINDINGS_PYTHON_SRC_PYXROOTDFINALIZE_HH_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters