Skip to content

Commit 6aea2e7

Browse files
committed
Python test code crash fix
1 parent 803739f commit 6aea2e7

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/Dataflow/Engine/Controller/PythonImpl.cc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -582,9 +582,15 @@ namespace SCIRun {
582582

583583
PythonImpl::PythonImpl(NetworkEditorController& nec, GlobalCommandFactoryHandle cmdFactory) : impl_(new PythonImplImpl), nec_(nec), cmdFactory_(cmdFactory)
584584
{
585-
nec_.connectNetworkExecutionFinished([this](int) { executionFromPythonFinish(0); });
586-
nec_.connectModuleAdded([this](const std::string& id, ModuleHandle m, ModuleCounter mc) { pythonModuleAddedSlot(id, m, mc); });
587-
nec_.connectModuleRemoved([this](const ModuleId& id) { pythonModuleRemovedSlot(id); });
585+
connections_.push_back(nec_.connectNetworkExecutionFinished([this](int) { executionFromPythonFinish(0); }));
586+
connections_.push_back(nec_.connectModuleAdded([this](const std::string& id, ModuleHandle m, ModuleCounter mc) { pythonModuleAddedSlot(id, m, mc); }));
587+
connections_.push_back(nec_.connectModuleRemoved([this](const ModuleId& id) { pythonModuleRemovedSlot(id); }));
588+
}
589+
590+
PythonImpl::~PythonImpl()
591+
{
592+
for (const auto& c : connections_)
593+
c.disconnect();
588594
}
589595

590596
void PythonImpl::setUnlockFunc(boost::function<void()> unlock)

src/Dataflow/Engine/Controller/PythonImpl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ namespace Engine {
4949
{
5050
public:
5151
PythonImpl(NetworkEditorController& nec, Core::Commands::GlobalCommandFactoryHandle cmdFactory);
52+
~PythonImpl();
5253
virtual boost::shared_ptr<PyModule> addModule(const std::string& name) override;
5354
virtual std::string removeModule(const std::string& id) override;
5455
virtual std::vector<boost::shared_ptr<PyModule>> moduleList() const override;
@@ -71,6 +72,7 @@ namespace Engine {
7172
NetworkEditorController& nec_;
7273
Core::Commands::GlobalCommandFactoryHandle cmdFactory_;
7374
boost::function<void()> unlock_;
75+
std::vector<boost::signals2::connection> connections_;
7476
};
7577

7678
}}}

0 commit comments

Comments
 (0)