So, I've started a thread, put a call of inexistent function and caught a error from that thread in the main app.
The problem is thread doesn't stop on error, but continue to throw errors.
Is there a way to reliably stop server if anything throws error within it?
[Solved] How to kill thread on any error?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
[Solved] How to kill thread on any error?
Last edited by 4aiman on Mon Jul 17, 2017 2:10 pm, edited 1 time in total.
- Luke100000
- Party member
- Posts: 232
- Joined: Mon Jul 22, 2013 9:17 am
- Location: Austria
- Contact:
Re: How to kill thread on any error?
If the thread crashes or finishes, the thread is dead. If you call thread:start() again it restarts.
So, the thread should not continue running, unless you restart it somewhere in the main app.
So, the thread should not continue running, unless you restart it somewhere in the main app.
Re: How to kill thread on any error?
That is what I have been told multiple times...
Yet, thread:getError() *still* returns the last error message from a thread forever.
Note the line.
Now, in love.update I have this
Should I put some clearly faulty invocation in a thread.lua (like "foo()", which doesn't exist anywhere) I'll get this:
message repeated over and over.
Either getError() recreates a thread or I don't know what to think...
How am I able to index local t if it is dead?
Certainly, i can set app.data_threads[ i ] to nil if there's a error, but that doesn't mean I'm closing/deleting a thread.
I can swear there's no any other place aside from the one I shown where I create a thread explicitly.
Are there any methods which do that implicitly?
Yet, thread:getError() *still* returns the last error message from a thread forever.
Code: Select all
if not data.updated then -- need that flag to bypass updates - simple and hackable
print("[Server]:","Client ".. data.nick .." needs to be updated")
local testport = 1
while app.data_ports[testport] do -- find a free channel, remember to free it @from a thread@!!!
testport = testport+1
end
local dataport = testport+app.data_port_start -- actual port for a thread server to listen to
local offload = {port=dataport, address=app.data_address} -- client AND server only need to know address:port info. Those may differ for various clients. Probably.
local thread = love.thread.newThread("thread.lua") -- making a thread
local chan = love.thread.getChannel(tostring(thread)) -- making up an exclusive channel
app.data_ports[testport] = true -- marking dataport as busy/taken
app.data_threads[#app.data_threads+1] = {t=thread, c=chan} -- storing thread and channel pointers locally
print("[Server]:","Offloading update to a thread ".. app.data_address ..":" .. dataport)
thread:start(chan, #app.data_threads) -- starting the thread
chan:push(offload) -- sending address:port to a thread
client:send("You need updates. Probably?",offload) -- sending address:port to client
return
end
Code: Select all
app.data_threads[#app.data_threads+1]
Now, in love.update I have this
Code: Select all
for i,ti in pairs(app.data_threads) do
t = ti.t
c = ti.c
local err = t:getError()
if err then
print("[Error (thread #".. i..")]:",err)
end
end
Code: Select all
[Error (thread #1)]: thread.lua:33: attempt to call global 'foo' (a nil value)
Either getError() recreates a thread or I don't know what to think...
How am I able to index local t if it is dead?
Certainly, i can set app.data_threads[ i ] to nil if there's a error, but that doesn't mean I'm closing/deleting a thread.
I can swear there's no any other place aside from the one I shown where I create a thread explicitly.
Are there any methods which do that implicitly?
Re: How to kill thread on any error?
Well maybe behavior should be changed to clear the error, if that is what expected of it. It's not like there is a good reason to keep last error forever.
Re: How to kill thread on any error?
Or you could make an parameter to choose if the error should be cleaned
- slime
- Solid Snayke
- Posts: 3132
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: How to kill thread on any error?
Thread:getError only returns an error until the Thread is successfully restarted.
Re: How to kill thread on any error?
Wow. Thanks everyone!
The thing which lead me into believeing thread's not killed was the ability to index that thread variable.
Kinda expected it to throw "attempt to index a nil value" error.
As for changing behavior, I guess if wiki said the error will be returned forever I'd just ignored it.
Oris there a way to remove that error message from the queue?
The thing which lead me into believeing thread's not killed was the ability to index that thread variable.
Kinda expected it to throw "attempt to index a nil value" error.
As for changing behavior, I guess if wiki said the error will be returned forever I'd just ignored it.
Oris there a way to remove that error message from the queue?
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: How to kill thread on any error?
Apart from it being nigh impossible, it'd be a bit weird if your environment were to suddenly change if the thread stopped, wouldn't it? And how would you get the error?
But it isn't a queue. If there is an (uncaught) error, the thread terminates, so it can't create a second error.
Who is online
Users browsing this forum: No registered users and 86 guests