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.
Showing the changes to TOOLS/lua/command-test.lua (1 of 5 files). Show all
Unified · Split
| @@ -64,4 +64,20 @@ mp.observe_property("vo-configured", "bool", function(_, v) · 63 unmodified lines | ||
| 64 | 64 | print("aborting sleep inf subprocess after timeout") |
| 65 | 65 | mp.abort_async_command(x) |
| 66 | 66 | end) |
| 67 | + | |
| 68 | + -- This should get killed on script exit. | |
| 69 | + mp.command_native_async({name = "subprocess", playback_only = false, | |
| 70 | + args = {"sleep", "inf"}}, function()end) | |
| 71 | + | |
| 72 | + -- Runs detached; should be killed on player exit (forces timeout) | |
| 73 | + mp.command_native({_flags={"async"}, name = "subprocess", | |
| 74 | + playback_only = false, args = {"sleep", "inf"}}) | |
| 75 | +end) | |
| 76 | + | |
| 77 | +mp.register_event("shutdown", function() | |
| 78 | + -- This "freezes" the script, should be killed via timeout. | |
| 79 | + print("freeze!") | |
| 80 | + local x = mp.command_native({name = "subprocess", playback_only = false, | |
| 81 | + args = {"sleep", "inf"}}) | |
| 82 | + print("done, killed=" .. utils.to_string(x.killed_by_us)) | |
| 67 | 83 | end) |