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

^T in shell launched as a parallel function ends the function... not what shell is currently doing

Started by Ninjarhh, 15 February 2013 - 05:57 AM
Ninjarhh #1
Posted 15 February 2013 - 06:57 AM
I have a script that runs a background rednet listener and a new shell by use of parallel.
then i try to terminate a program that the new shell is running it just ends the parallel…


function runShell()
	shell.run("shell", "/bin/start-up")
end
function runControl()
	shell.run("rednet_control")
end
parallel.waitForAny(runShell, runControl)
os.shutdown()

Any clues as to how i avoid this? thanks
Lyqyd #2
Posted 15 February 2013 - 07:53 AM
The parallel call distributes the events between both coroutines, so it's sending the terminate event to both your rednet coroutine and your foreground coroutine. The rednet coroutine is probably terminating, which ends the waitForAny. The shell coroutine is probably handling it correctly. Try using os.pullEventRaw in your rednet coroutine instead of os.pullEvent.
Ninjarhh #3
Posted 15 February 2013 - 08:15 AM
I tried setting os.pullEvent as os.pullEventRaw in rednet_control which, obviously, affected all programs…
i then tried doing this in the main script:

_os = os
os.pullEvent = os.pullEventRaw

And tried passing _os as os in the environment args for os.run for rednet_control… did not work.
Lyqyd #4
Posted 15 February 2013 - 08:55 AM
No, try using it, not overriding it.


while true do
  event, id, message, dist =os.pullEventRaw("rednet_message")
  --usual code to handle messages.
end
Ninjarhh #5
Posted 15 February 2013 - 09:01 AM
Ooooooh. works perfectly… don't know how i missed that on the docs.
thanks a bunch guy :)/>