File tree Expand file tree Collapse file tree 1 file changed +14
-12
lines changed
subprojects/robotpy-wpilib/wpilib/src/rpy Expand file tree Collapse file tree 1 file changed +14
-12
lines changed Original file line number Diff line number Diff line change 2020using namespace frc ;
2121using namespace pybind11 ::literals;
2222
23+ // Hang the thread since returning to the caller is going to crash when we try
24+ // to obtain the GIL again
25+ // - this is a daemon thread so it's fine?
26+ // - Python 3.14 does this too
27+ static void _hang_thread_if_finalizing () {
28+ if (Py_IsFinalizing ()) {
29+ while (true ) {
30+ std::this_thread::sleep_for (std::chrono::seconds (1000 ));
31+ }
32+ }
33+ }
34+
2335PyNotifier::PyNotifier (std::function<void ()> handler) {
2436 if (!handler) {
2537 throw FRC_MakeError (err::NullParameter, " handler" );
@@ -67,21 +79,11 @@ PyNotifier::PyNotifier(std::function<void()> handler) {
6779 }
6880 }
6981 } catch (...) {
70- if (Py_IsFinalizing ()) {
71- // Hang the thread since returning to the caller is going to crash
72- // when we try to obtain the GIL again
73- // - this is a daemon thread so it's fine?
74- // - Python 3.14 does this too
75- while (true ) {}
76- }
77-
82+ _hang_thread_if_finalizing ();
7883 throw ;
7984 }
8085
81- if (Py_IsFinalizing ()) {
82- // see above
83- while (true ) {}
84- }
86+ _hang_thread_if_finalizing ();
8587 });
8688
8789 py::gil_scoped_acquire acquire;
You can’t perform that action at this time.
0 commit comments