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 20
20
using namespace frc ;
21
21
using namespace pybind11 ::literals;
22
22
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
+
23
35
PyNotifier::PyNotifier (std::function<void ()> handler) {
24
36
if (!handler) {
25
37
throw FRC_MakeError (err::NullParameter, " handler" );
@@ -67,21 +79,11 @@ PyNotifier::PyNotifier(std::function<void()> handler) {
67
79
}
68
80
}
69
81
} 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 ();
78
83
throw ;
79
84
}
80
85
81
- if (Py_IsFinalizing ()) {
82
- // see above
83
- while (true ) {}
84
- }
86
+ _hang_thread_if_finalizing ();
85
87
});
86
88
87
89
py::gil_scoped_acquire acquire;
You can’t perform that action at this time.
0 commit comments