This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
LNETeam's profile picture

Terminate background parallels

Started by LNETeam, 21 September 2014 - 03:50 PM
LNETeam #1
Posted 21 September 2014 - 05:50 PM
Quick question.

Lets say I do this:


local ops = {function() shell.run("shell") end, mon (this is a internal function)}
parallel.waitForAny(unpack(ops))

So in theory I have a background process. Now, from another program, I wanted to terminate the 'mon' process, is that possible?


> some_program --kill

This terminates the mon 'thread'.
KingofGamesYami #2
Posted 21 September 2014 - 06:13 PM
You could communicate through os.queueEvent and os.pullEvent.


--#bla bla bla stuff

--#now we want to kill it
os.queueEvent( "kill_mon" )
And in mon:

local event = { os.pullEvent() }
if event[ 1 ] == "kill_mon" then
  return
end

Also, if you want to kill only one, you would have to use parallel.waitForAll.
LNETeam #3
Posted 21 September 2014 - 06:23 PM
Thanks it works

Wait. From a different program?
Just kidding, had to do some fiddling
Edited on 21 September 2014 - 04:45 PM