@@ -26,7 +26,6 @@ struct pyMOOSException : std::exception {
2626 }
2727 char const * what () const throw () {
2828 return s_.c_str ();
29- return " lala" ;/* return s_.c_str();*/
3029 }
3130 std::string s_;
3231};
@@ -47,17 +46,9 @@ class AsyncCommsWrapper : public MOOS::MOOSAsyncCommClient {
4746public:
4847
4948 ~AsyncCommsWrapper (){
50- // AsyncCommsWrapper::Close(true);
51- // BASE::~BASE();
52- Py_BEGIN_ALLOW_THREADS
53- // PyGILState_STATE gstate = PyGILState_Ensure();
54- BASE::Close (true );
55- // PyGILState_Release(gstate);
56- Py_END_ALLOW_THREADS
57-
49+ Close (true );
5850 }
5951
60-
6152 bool Run (const std::string & sServer , int Port, const std::string & sMyName ) {
6253 return BASE::Run (sServer , Port, sMyName , 0 );// Comms Tick not used in Async version
6354 }
@@ -96,7 +87,9 @@ class AsyncCommsWrapper : public MOOS::MOOSAsyncCommClient {
9687 bool Close (bool nice){
9788 Py_BEGIN_ALLOW_THREADS
9889 // PyGILState_STATE gstate = PyGILState_Ensure();
99- this ->BASE ::~BASE ();
90+ closing_ = true ;
91+ BASE::Close (true );
92+
10093 // PyGILState_Release(gstate);
10194 Py_END_ALLOW_THREADS
10295 }
@@ -135,13 +128,14 @@ class AsyncCommsWrapper : public MOOS::MOOSAsyncCommClient {
135128 }
136129
137130 bool on_mail () {
138-
139131 bool bResult = false ;
140132
141133 PyGILState_STATE gstate = PyGILState_Ensure ();
142134 try {
143- bp::object result = on_mail_object_ ();
144- bResult = bp::extract<bool >(result);
135+ if (!closing_){
136+ bp::object result = on_mail_object_ ();
137+ bResult = bp::extract<bool >(result);
138+ }
145139 } catch (const bp::error_already_set& e) {
146140 PyGILState_Release (gstate);
147141 throw pyMOOSException (
@@ -151,7 +145,6 @@ class AsyncCommsWrapper : public MOOS::MOOSAsyncCommClient {
151145 PyGILState_Release (gstate);
152146
153147 return bResult;
154-
155148 }
156149
157150 static bool active_queue_delegate (CMOOSMsg & M, void * pParam) {
@@ -220,7 +213,9 @@ class AsyncCommsWrapper : public MOOS::MOOSAsyncCommClient {
220213 /* * callback functions (stored) */
221214 bp::object on_connect_object_;
222215 bp::object on_mail_object_;
223-
216+
217+ /* * close connection flag */
218+ bool closing_;
224219};
225220}
226221;// namesapce
0 commit comments