Skip to content

Commit 673b52e

Browse files
committed
not elegant fix
1 parent 1d8509f commit 673b52e

2 files changed

Lines changed: 12 additions & 26 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ if(NOT DEFINED CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
2626
endif()
2727

2828

29-
30-
3129
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${Boost_INCLUDE_DIRS} ${MOOS_INCLUDE_DIRS})
3230

3331
set(src
@@ -46,7 +44,6 @@ set_target_properties(pymoos
4644
PREFIX "")
4745

4846

49-
5047
file(GLOB ExampleFiles ${CMAKE_SOURCE_DIR}/Documentation/examples/*.py)
5148
add_custom_target(copy)
5249
get_target_property(pymoosLocation pymoos LOCATION)
@@ -56,13 +53,7 @@ foreach(ExampleFile ${ExampleFiles})
5653
COMMAND ${CMAKE_COMMAND} -E
5754
copy ${ExampleFile} ${pymoosDir})
5855
endforeach()
59-
add_dependencies(pymoos copy)
60-
61-
56+
add_dependencies(pymoos copy)
6257

6358

6459
TARGET_LINK_LIBRARIES(pymoos ${Boost_LIBRARIES} ${PYTHON_LIBRARIES} ${MOOS_LIBRARIES})
65-
66-
67-
68-

pyMOOS.cpp

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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 {
4746
public:
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

Comments
 (0)