[hydra-commits] ken.hunt: branch techdemo/ken.hunt/embeddedPythonTest r631 - /techdemo/team/k...
SVN commits to the Hydra project
hydra-commits at lists.digium.com
Thu May 20 15:07:22 CDT 2010
Author: ken.hunt
Date: Thu May 20 15:07:22 2010
New Revision: 631
URL: https://origsvn.digium.com/svn-view/hydra?view=rev&rev=631
Log:
python thread testing
Modified:
techdemo/team/ken.hunt/embeddedPythonTest/threadtest/pyworkqueue.cpp
techdemo/team/ken.hunt/embeddedPythonTest/threadtest/threadtest.cpp
Modified: techdemo/team/ken.hunt/embeddedPythonTest/threadtest/pyworkqueue.cpp
URL: https://origsvn.digium.com/svn-view/hydra/techdemo/team/ken.hunt/embeddedPythonTest/threadtest/pyworkqueue.cpp?view=diff&rev=631&r1=630&r2=631
==============================================================================
--- techdemo/team/ken.hunt/embeddedPythonTest/threadtest/pyworkqueue.cpp (original)
+++ techdemo/team/ken.hunt/embeddedPythonTest/threadtest/pyworkqueue.cpp Thu May 20 15:07:22 2010
@@ -22,6 +22,7 @@
: mQid(id),
mInitialized(false),
mPyInitialized(false),
+ mPyReleased(false),
mPaused(paused),
mFinished(false),
mThread(boost::bind(&PyWorkQueuePriv::Execute, this))
@@ -30,6 +31,17 @@
~PyWorkQueuePriv()
{
+ ReleasePython();
+ }
+
+ void ReleasePython()
+ {
+ if (mPyReleased)
+ {
+ return;
+ }
+ mPyReleased = true;
+
// Clear my thread state
PyEval_AcquireLock();
PyThreadState_Swap(NULL);
@@ -47,6 +59,7 @@
std::string mQid;
bool mInitialized;
bool mPyInitialized;
+ bool mPyReleased;
bool mFinished;
bool mPaused;
std::list<IWorkPtr> mQueue;
@@ -102,6 +115,7 @@
*/
void PyWorkQueue::Terminate()
{
+ mImpl->ReleasePython();
mImpl->mFinished = true;
mImpl->mPaused = false;
mImpl->mPauseCondition.notify_all(); // In case the thread was waiting on the PauseCondition.
Modified: techdemo/team/ken.hunt/embeddedPythonTest/threadtest/threadtest.cpp
URL: https://origsvn.digium.com/svn-view/hydra/techdemo/team/ken.hunt/embeddedPythonTest/threadtest/threadtest.cpp?view=diff&rev=631&r1=630&r2=631
==============================================================================
--- techdemo/team/ken.hunt/embeddedPythonTest/threadtest/threadtest.cpp (original)
+++ techdemo/team/ken.hunt/embeddedPythonTest/threadtest/threadtest.cpp Thu May 20 15:07:22 2010
@@ -103,6 +103,7 @@
mainThreadState = PyThreadState_Get();
PyEval_ReleaseLock();
+ // This is a work queue customized to handle threaded python tasks.
PyWorkQueue wqueue1("wq1", mainThreadState, true);
PyWorkQueue wqueue2("wq2", mainThreadState, true);
@@ -150,11 +151,22 @@
sleep(5);
+ std::cout << "Post sleep." << std::endl;
+
wqueue1.Terminate();
wqueue2.Terminate();
+
+ std::cout << "Post Terminate." << std::endl;
+
wqueue1.Join();
wqueue2.Join();
+ std::cout << "Post Join." << std::endl;
+
PyEval_AcquireLock();
- Py_Finalize();
+
+ std::cout << "Post AcquireLock." << std::endl;
+
+ // This call is causing an exception on Windows!
+ // Py_Finalize();
}
More information about the asterisk-scf-commits
mailing list