-
Notifications
You must be signed in to change notification settings - Fork 146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LaunchService.shutdown() fails to terminate run loop #126
Comments
I think this issue comes from using
If I modify the script like so (I'm avoiding the shebang by invoking with import sys
import time
import threading
from launch import LaunchDescription
from launch import LaunchService
import launch_ros.actions
ls = None
def run():
global ls
ld = LaunchDescription([
launch_ros.actions.Node(
package='demo_nodes_cpp', node_executable='listener', output='screen'),
])
ls = LaunchService()
ls.include_launch_description(ld)
ls.run()
def main():
t = threading.Thread(target=run)
t.start()
time.sleep(5) # wait for listener to fully start
assert ls is not None
ls.shutdown()
t.join()
if __name__=="__main__":
main() I get this:
Which is a combination of errors, some are ours, e.g. the See: launch/launch/launch/utilities/signal_management.py Lines 41 to 42 in 053a5f7
I guess my assumption was that running LaunchService from a thread would be ok so long as you constructed it in the main thread (what your script does), but perhaps none of the tests do all of that and execute a process. This launch file does work: import threading
import time
import launch.actions
from launch import LaunchDescription
from launch import LaunchService
def main():
ld = LaunchDescription([launch.actions.LogInfo(msg='Hello World')])
ls = LaunchService()
ls.include_launch_description(ld)
t = threading.Thread(target=ls.run)
t.start()
time.sleep(5) # wait for listener to fully start
ls.shutdown()
t.join()
if __name__ == '__main__':
main() I'll see if I can reproduce your exact issue with Python 3.5 in Xenial. |
I can reproduce your issue on Xenial as well. So the question is what to do about it. For now I'd advise never running If running it in a thread is a must, I can look at the child watcher policies that asyncio has. There is I'll wait to hear from you guys about why you need to run in a thread, and if it's not a hard requirement I'll likely just document that you shouldn't and put a better/earlier warning when you try to do that. |
There's a little info about the child process watchers here: https://stackoverflow.com/questions/48604341/what-is-event-loop-policy-and-why-is-it-needed-in-python-asyncio |
What I'm trying to do is write some integration tests for my node in pytest. I was trying to use I needed to put The alternatives I can think of are:
|
Ok, so in ROS 1 the equivalent to this was I can see the allure of using So I guess we should look at how to support running outside of the main thread, but that's not something I have time to dig into at the moment and in my opinion there's a chance it just never works right, especially with Python 3.5.2. Lots of The other thing I'll mention is that when you use |
I'll also say that for now we're still using the legacy system in |
I've got no problems with going to a newer Python version, but based on your test with 3.7, it doesn't really solve my problem. It just gets me a better error message :-) I'll take a look at what @dirk-thomas is doing. I'd like to follow the same pattern as the rest of the ROS code, but I just couldn't figure out how to use the existing In the meantime, I'll work around |
That's true, but it might also be required for one of the potential solutions for multi-threading (like the |
Also, using |
For now, I think I'll just spawn |
I just encountered this exact same problem and then stumbled on this issue (woo google!). Based on this comment here it sure seems like LaunchService.run is intended to be runnable from another thread, right? If LaunchService.shutdown is not meant to shut down a LaunchService that got run on another thread, what's it supposed to be for? Or are you only meant to do LaunchService.run from the main thread, and then some other worker thread calls LaunchService.shutdown? Thanks, |
I recommend not running launch service in anything but the main thread (it is special in Python). That comment implies that shutdown may be called from a non-main thread but will do nothing if the launch service isn't running. |
Alright, I just stumbled upon this issue too. It's quite inconvenient, as pushing the service to a thread instead of pushing the tests (as @pbaughman had to do) simplifies things quite a bit. I'll dig in a bit. |
Ok, there seems to be a fundamental limitation in |
Bug report
Required Info:
Steps to reproduce issue
Run the following python code
Expected behavior
I expect the listener executable to terminate and the python code to exit.
Actual behavior
The python script produces the following output but never terminates.
Additional information
The listener executable in fact terminates when the SIGINT is sent and remains as a zombie process.
The text was updated successfully, but these errors were encountered: