Skip to content

Commit 1af420b

Browse files
Merge pull request #24 from YoheiKakiuchi/fix_shutdown
FIX: shutdown correctly
2 parents a58bcc6 + 32dc7e4 commit 1af420b

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

src/plugin/PythonProcess.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,22 @@ class PythonProcess::Impl
7373
//xeus::xshell_default_runner* p_runner;
7474
xeus::non_blocking_runner* p_runner;
7575

76-
QTimer timer;
77-
7876
bool use_jupyter;
7977

78+
#ifdef USE_BLOCKING
79+
QTimer timer;
80+
#else
8081
Runner *qrunner;
82+
#endif
8183
};
84+
8285
}
8386

8487
PythonProcess::Impl::Impl(PythonProcess *_self) : self(_self), interpreter(nullptr), python(nullptr),
85-
p_runner(nullptr), timer(_self), use_jupyter(false)
88+
p_runner(nullptr), use_jupyter(false)
89+
#ifdef USE_BLOCKING
90+
,timer(_self)
91+
#endif
8692
{
8793
}
8894

@@ -149,6 +155,8 @@ void PythonProcess::shutdown_impl()
149155
DEBUG_PRINT();
150156
INFO_STREAM(" shutdown_impl");
151157
impl->kernel->get_server().stop();
158+
INFO_STREAM(" shutdown_impl::stopped");
159+
152160
QCoreApplication::quit(); // [TODO] exit choreonoid, is it OK?
153161
}
154162

@@ -181,6 +189,7 @@ bool PythonProcess::setupPython()
181189
std::unique_ptr<xeus::xcontext> context = xeus::make_zmq_context();
182190
Impl::interpreter_ptr interpreter_(new cnoid_interpreter());
183191
impl->interpreter = dynamic_cast<cnoid_interpreter *>(interpreter_.get());
192+
impl->interpreter->process = this;
184193
xeus::xconfiguration config = xeus::load_configuration(connection_file);
185194
impl->kernel = Impl::kernel_ptr(new xeus::xkernel(config,
186195
xeus::get_user_name(),
@@ -204,16 +213,18 @@ bool PythonProcess::setupPython()
204213
xpyt::make_python_debugger,
205214
debugger_config));
206215
impl->kernel->start();
207-
#if 0
216+
#ifdef USE_BLOCKING
208217
// timered non_blocking poll
209218
impl->timer.setInterval(0);
210219
connect(&(impl->timer), &QTimer::timeout, this, &PythonProcess::proc);
211220
impl->timer.start();
212-
#endif
221+
#else
222+
// non-blocking using thread
213223
impl->qrunner = new Runner(impl->self);
214224
connect(impl->qrunner, &Runner::sendRequest,
215225
this, &PythonProcess::procRequest, Qt::BlockingQueuedConnection);
216226
impl->qrunner->start();
227+
#endif
217228
} else {
218229
std::unique_ptr<xeus::xcontext> context = xeus::make_zmq_context();
219230
Impl::interpreter_ptr interpreter_(new cnoid_interpreter());
@@ -274,6 +285,7 @@ void PythonProcess::procRequest()
274285
proc();
275286
}
276287

288+
#ifndef USE_BLOCKING
277289
class Runner::Impl {
278290
public:
279291
Impl() { };
@@ -297,4 +309,4 @@ void Runner::run()
297309
}
298310
}
299311
}
300-
312+
#endif

src/plugin/PythonProcess.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public Q_SLOTS:
5050
Impl *impl;
5151
};
5252

53+
#ifndef USE_BLOCKING
5354
class Runner : public QThread
5455
{
5556
Q_OBJECT;
@@ -65,5 +66,7 @@ class Runner : public QThread
6566
Impl *impl;
6667
};
6768

69+
#endif
70+
6871
}
6972
#endif

src/plugin/cnoid_interpreter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ nl::json cnoid_interpreter::is_complete_request_impl(const std::string& code)
113113

114114
void cnoid_interpreter::shutdown_request_impl()
115115
{
116+
std::cerr << "shutdown_request_impl" << std::endl;
116117
if (!!process) {
118+
std::cerr << "call shutdown_impl()" << std::endl;
117119
process->shutdown_impl();
118120
}
119121
}

0 commit comments

Comments
 (0)