Skip to content

Commit

Permalink
python: release GIL when running server (#1458)
Browse files Browse the repository at this point in the history
Since running the server can be a blocking function, we need to release
the GIL so that other Python threads can run. This also means we no
longer need to poll for the server to finish running by setting the
blocking argument to True.

Signed-off-by: David Lechner <[email protected]>
  • Loading branch information
dlech authored Apr 26, 2022
1 parent 07bbeb2 commit 0a5828e
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 13 deletions.
6 changes: 1 addition & 5 deletions examples/scripts/python_api/testFixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
# python3 examples/scripts/python_api/helperFixture.py

import os
import time

from ignition.common import set_verbosity
from ignition.gazebo import TestFixture, World, world_entity
Expand Down Expand Up @@ -75,10 +74,7 @@ def on_post_udpate_cb(_info, _ecm):
helper.finalize()

server = helper.server()
server.run(False, 1000, False)

while(server.is_running()):
time.sleep(0.1)
server.run(True, 1000, False)

print('iterations ', iterations)
print('post_iterations ', post_iterations)
Expand Down
1 change: 1 addition & 0 deletions python/src/ignition/gazebo/Server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ void defineGazeboServer(pybind11::object module)
.def(pybind11::init<ignition::gazebo::ServerConfig &>())
.def(
"run", &ignition::gazebo::Server::Run,
pybind11::call_guard<pybind11::gil_scoped_release>(),
"Run the server. By default this is a non-blocking call, "
" which means the server runs simulation in a separate thread. Pass "
" in true to the _blocking argument to run the server in the current "
Expand Down
6 changes: 1 addition & 5 deletions python/test/testFixture_TEST.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# limitations under the License.

import os
import time
import unittest

from ignition.common import set_verbosity
Expand Down Expand Up @@ -56,10 +55,7 @@ def on_udpate_cb(_info, _ecm):
helper.finalize()

server = helper.server()
server.run(False, 1000, False)

while(server.is_running()):
time.sleep(0.1)
server.run(True, 1000, False)

self.assertEqual(1000, pre_iterations)
self.assertEqual(1000, iterations)
Expand Down
4 changes: 1 addition & 3 deletions tutorials/python_interfaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ helper.finalize()
- **Step 5**: Run the server

```python
server.run(False, 1000, False)
while(server.is_running()):
time.sleep(0.1)
server.run(True, 1000, False)
```

# Run the example
Expand Down

0 comments on commit 0a5828e

Please sign in to comment.