summaryrefslogtreecommitdiffstats
path: root/TOOLS
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2018-05-13 13:48:47 +0200
committerwm4 <wm4@nowhere>2018-05-24 19:56:34 +0200
commit7428cc51496ca8e56600fdc4034b8f55720f09f9 (patch)
tree4e09e1818b2e60ccf1db3b1ba04cb227275a658f /TOOLS
parent4e05f75261d997cfc48227f5ac1ab8f18101c437 (diff)
downloadmpv-7428cc51496ca8e56600fdc4034b8f55720f09f9.tar.bz2
mpv-7428cc51496ca8e56600fdc4034b8f55720f09f9.tar.xz
client API: kill async commands on termination
This affects async commands started by client API, commands with async capability run in a sync way by client API (think mpv_command_node() with "subprocess"), and detached async work. Since scripts might want to do some cleanup work (that might involve launching processes, don't ask), we don't unconditionally kill everything on exit, but apply an arbitrary timeout of 2 seconds until async commands are aborted.
Diffstat (limited to 'TOOLS')
-rw-r--r--TOOLS/lua/command-test.lua16
1 files changed, 16 insertions, 0 deletions
diff --git a/TOOLS/lua/command-test.lua b/TOOLS/lua/command-test.lua
index 1a8d86b4dd..79c1127cbf 100644
--- a/TOOLS/lua/command-test.lua
+++ b/TOOLS/lua/command-test.lua
@@ -64,4 +64,20 @@ mp.observe_property("vo-configured", "bool", function(_, v)
print("aborting sleep inf subprocess after timeout")
mp.abort_async_command(x)
end)
+
+ -- This should get killed on script exit.
+ mp.command_native_async({name = "subprocess", playback_only = false,
+ args = {"sleep", "inf"}}, function()end)
+
+ -- Runs detached; should be killed on player exit (forces timeout)
+ mp.command_native({_flags={"async"}, name = "subprocess",
+ playback_only = false, args = {"sleep", "inf"}})
+end)
+
+mp.register_event("shutdown", function()
+ -- This "freezes" the script, should be killed via timeout.
+ print("freeze!")
+ local x = mp.command_native({name = "subprocess", playback_only = false,
+ args = {"sleep", "inf"}})
+ print("done, killed=" .. utils.to_string(x.killed_by_us))
end)