PythonProxyNotificationHandler::OnEventGenericHook acquires the Python GIL before executing (#3904)
- Protected python execution of OnEventGenericHook by trying to lock the GIL and show a descriptive error when it was not possible to lock. - Improved mechanism to lock python mutex and GIL in PhytonSystemComponent. Acquiring/releasing GIL once per thread. - Added unit test to verify errors are fired when trying to execute OnEventGenericHook from another thread (as it should not able to acquire the GIL). - Improved python threading tests to actually using python buses. Signed-off-by: moraaar moraaar@amazon.com
This commit is contained in:
@@ -37,6 +37,15 @@ namespace UnitTest
|
||||
using EvaluationMap = AZStd::unordered_map<int, int>; // tag to count
|
||||
EvaluationMap m_evaluationMap;
|
||||
|
||||
AZStd::mutex m_lock;
|
||||
|
||||
void CleanUp()
|
||||
{
|
||||
AZStd::lock_guard<decltype(m_lock)> lock(m_lock);
|
||||
m_evaluateMessage = {};
|
||||
m_evaluationMap.clear();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// TraceMessageDrillerBus
|
||||
void OnPrintf(const char* window, const char* message) override
|
||||
@@ -46,6 +55,8 @@ namespace UnitTest
|
||||
|
||||
void OnOutput(const char* window, const char* message) override
|
||||
{
|
||||
AZStd::lock_guard<decltype(m_lock)> lock(m_lock);
|
||||
|
||||
if (m_evaluateMessage)
|
||||
{
|
||||
int key = m_evaluateMessage(window, message);
|
||||
|
||||
Reference in New Issue
Block a user