Skip to content

Commit 5228864

Browse files
Release the gil on BeamOn
1 parent b0f3ed0 commit 5228864

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

source/geant4_pybind.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ class G4PyCoutDestination : public G4coutDestination {
2222
public:
2323
G4int ReceiveG4cout(const G4String &coutString) override
2424
{
25+
py::gil_scoped_acquire gil;
2526
auto pystdout = py::module_::import("sys").attr("stdout").attr("write");
2627
pystdout(coutString);
2728
return 0;
2829
}
2930

3031
G4int ReceiveG4cerr(const G4String &cerrString) override
3132
{
33+
py::gil_scoped_acquire gil;
3234
auto pystderr = py::module_::import("sys").attr("stderr").attr("write");
3335
pystderr(cerrString);
3436
return 0;

source/intercoms/pyG4UImanager.cc

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,18 @@ void export_G4UImanager(py::module &m)
1616

1717
.def("GetCurrentValues", &G4UImanager::GetCurrentValues)
1818
.def("ExecuteMacroFile", &G4UImanager::ExecuteMacroFile)
19-
.def("ApplyCommand", py::overload_cast<const char *>(&G4UImanager::ApplyCommand))
20-
.def("ApplyCommand", py::overload_cast<const G4String &>(&G4UImanager::ApplyCommand))
19+
.def("ApplyCommand",
20+
[](G4UImanager &self, const char *command) {
21+
py::gil_scoped_release gil;
22+
self.ApplyCommand(command);
23+
})
24+
25+
.def("ApplyCommand",
26+
[](G4UImanager &self, const G4String &command) {
27+
py::gil_scoped_release gil;
28+
self.ApplyCommand(command);
29+
})
30+
2131
.def("CreateHTML", &G4UImanager::CreateHTML, py::arg("dir") = "/")
2232
.def("SetMacroSearchPath", &G4UImanager::SetMacroSearchPath)
2333
.def("GetMacroSearchPath", &G4UImanager::GetMacroSearchPath)

source/run/pyG4RunManager.cc

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,14 @@ void export_G4RunManager(py::module &m)
3838
.def("GetPrintProgress", &G4RunManager::GetPrintProgress)
3939

4040
.def("Initialize", &G4RunManager::Initialize)
41-
.def("BeamOn", &G4RunManager::BeamOn, py::arg("n_event"),
42-
py::arg("macroFile") = static_cast<const char *>(nullptr), py::arg("n_select") = -1, "Starts event loop.")
41+
.def(
42+
"BeamOn",
43+
[](G4RunManager &self, G4int n_event, const char *macroFile = 0, G4int n_select = -1) {
44+
py::gil_scoped_release gil;
45+
self.BeamOn(n_event, macroFile, n_select);
46+
},
47+
py::arg("n_event"), py::arg("macroFile") = static_cast<const char *>(nullptr), py::arg("n_select") = -1,
48+
"Starts event loop.")
4349

4450
.def("SetUserInitialization",
4551
[](G4RunManager &self, G4VUserDetectorConstruction *detector) {
@@ -140,7 +146,9 @@ void export_G4RunManager(py::module &m)
140146
py::arg("topologyIsChanged") = true)
141147

142148
.def("DumpRegion", py::overload_cast<const G4String &>(&G4RunManager::DumpRegion, py::const_))
143-
.def("DumpRegion", py::overload_cast<G4Region *>(&G4RunManager::DumpRegion, py::const_))
149+
.def("DumpRegion", py::overload_cast<G4Region *>(&G4RunManager::DumpRegion, py::const_),
150+
py::arg("region") = static_cast<G4Region *>(nullptr))
151+
144152
.def("rndmSaveThisRun", &G4RunManager::rndmSaveThisRun)
145153
.def("rndmSaveThisEvent", &G4RunManager::rndmSaveThisEvent)
146154
.def("RestoreRandomNumberStatus", &G4RunManager::RestoreRandomNumberStatus)

0 commit comments

Comments
 (0)