Skip to content
Snippets Groups Projects
Commit 8a78414a authored by Gloria Corti's avatar Gloria Corti
Browse files

Merge branch 'cherry-pick-820bf659' into 'sim10-patches'

Do not arbitrarily release Python GIL in HLTControlFlowMgr (backport for Sim10)

See merge request !3949
parents 44b6301f c9752eb5
No related branches found
No related tags found
1 merge request!3949Do not arbitrarily release Python GIL in HLTControlFlowMgr (backport for Sim10)
Pipeline #5127642 passed
......@@ -21,7 +21,6 @@ gaudi_add_module(HLTScheduler
src/ExecutionReportsWriter.cpp
src/HLTControlFlowMgr.cpp
LINK
Python::Python
cppgsl::cppgsl
Gaudi::GaudiKernel
LHCb::LHCbAlgsLib
......
......@@ -38,7 +38,6 @@
#include "ThreadPool.h"
#include "tbb/task_arena.h"
#include "tbb/task_scheduler_observer.h"
#include <Python.h>
#include <algorithm>
#include <chrono>
#include <condition_variable>
......@@ -320,13 +319,6 @@ namespace {
void on_scheduler_entry( bool ) override { m_thread_count++; }
void on_scheduler_exit( bool ) override { m_thread_count--; }
};
/// Helper class to temporarily release the GIL to allow other threads to take it.
struct PyGILReleaseGuard {
PyGILReleaseGuard() : state( PyEval_SaveThread() ) {}
~PyGILReleaseGuard() { PyEval_RestoreThread( state ); }
PyThreadState* state;
};
} // namespace
StatusCode HLTControlFlowMgr::initialize() {
......@@ -816,50 +808,44 @@ StatusCode HLTControlFlowMgr::nextEvent( int maxevt ) {
[]( uint64_t total, auto const& counter ) { return total + counter.sum().count(); } );
};
{
// Release the GIL so that XMLSummarySvc can acquire it from within the event execution thread.
// Probably XMLSummarySvc fails with multiple threads but it should be redone anyway.
PyGILReleaseGuard gilRelease;
while ( maxevt < 0 || m_nextevt < maxevt ) {
if ( m_shutdown_now ) {
shutdown_threadpool();
while ( not empty() ) pop();
return StatusCode::FAILURE;
}
if ( m_startTimeAtEvt == m_nextevt ) {
auto currtime = std::time( nullptr );
info() << "Timing started at: " << std::put_time( std::localtime( &currtime ), "%T" ) << endmsg;
m_alloc_tracker->beginTracking();
startTimeAndTicks.emplace( Clock::now(), getTotalWorkerTicks() );
}
if ( m_stopTimeAtEvt == m_nextevt ) {
endTimeAndTicks.emplace( Clock::now(), getTotalWorkerTicks() );
m_alloc_tracker->endTracking();
auto currtime = std::time( nullptr );
info() << "Timing stopped at: " << std::put_time( std::localtime( &currtime ), "%T" ) << endmsg;
}
auto evtContext = createEventContext();
if ( !evtContext.valid() ) {
if ( m_nextevt == -1 ) break; // finished
shutdown_threadpool();
return StatusCode::FAILURE; // else we have an success --> exit loop
}
push( std::move( evtContext ) );
pop();
} // end main loop on finished events
if ( !endTimeAndTicks ) {
while ( maxevt < 0 || m_nextevt < maxevt ) {
if ( m_shutdown_now ) {
shutdown_threadpool();
while ( not empty() ) pop();
return StatusCode::FAILURE;
}
if ( m_startTimeAtEvt == m_nextevt ) {
auto currtime = std::time( nullptr );
info() << "Timing started at: " << std::put_time( std::localtime( &currtime ), "%T" ) << endmsg;
m_alloc_tracker->beginTracking();
startTimeAndTicks.emplace( Clock::now(), getTotalWorkerTicks() );
}
if ( m_stopTimeAtEvt == m_nextevt ) {
endTimeAndTicks.emplace( Clock::now(), getTotalWorkerTicks() );
m_stopTimeAtEvt = m_finishedEvt;
m_alloc_tracker->endTracking();
auto currtime = std::time( nullptr );
info() << "Timing stopped at: " << std::put_time( std::localtime( &currtime ), "%T" ) << endmsg;
}
auto evtContext = createEventContext();
if ( !evtContext.valid() ) {
if ( m_nextevt == -1 ) break; // finished
shutdown_threadpool();
return StatusCode::FAILURE; // else we have an success --> exit loop
}
push( std::move( evtContext ) );
pop();
} // end main loop on finished events
if ( !endTimeAndTicks ) {
endTimeAndTicks.emplace( Clock::now(), getTotalWorkerTicks() );
m_stopTimeAtEvt = m_finishedEvt;
m_alloc_tracker->endTracking();
}
shutdown_threadpool();
while ( not empty() ) pop();
shutdown_threadpool();
while ( not empty() ) pop();
releaseEvtSelContext().ignore();
}
releaseEvtSelContext().ignore();
if ( !startTimeAndTicks ) {
info() << "---> Loop over " << m_finishedEvt << " Events Finished - "
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment