Skip to content

Commit

Permalink
ParallelAlgo/Gadget : Fix Python 3.10 shutdown crash
Browse files Browse the repository at this point in the history
  • Loading branch information
johnhaddon committed Feb 12, 2024
1 parent 13255e0 commit 265be18
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/Gaffer/ParallelAlgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@ using UIThreadCallHandlers = std::stack<ParallelAlgo::UIThreadCallHandler>;
std::unique_lock<std::mutex> lockUIThreadCallHandlers( UIThreadCallHandlers *&handlers )
{
static std::mutex g_mutex;
static UIThreadCallHandlers g_handlers;
handlers = &g_handlers;
// Deliberately leaking `g_handlers` here as otherwise we get crashes
// when it contains handlers implemented in Python, because Python has
// already shut down before static destructors are run, and we can't
// destroy a Python object after Python has shut down.
static UIThreadCallHandlers *g_handlers = new UIThreadCallHandlers;
handlers = g_handlers;
return std::unique_lock<std::mutex>( g_mutex );
}

Expand Down
5 changes: 3 additions & 2 deletions src/GafferUI/Gadget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,9 @@ Gadget::IdleSignal &Gadget::idleSignal()

Gadget::IdleSignal &Gadget::idleSignalAccessedSignal()
{
static IdleSignal g_idleSignalAccessedSignal;
return g_idleSignalAccessedSignal;
// See above.
static IdleSignal *g_idleSignalAccessedSignal = new IdleSignal;
return *g_idleSignalAccessedSignal;
}

void Gadget::styleChanged()
Expand Down

0 comments on commit 265be18

Please sign in to comment.