Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I kill a task / coroutine in Julia?

using HttpServer

http = HttpHandler() do request::Request, response::Response
    show(request)
    Response("Hello there")
end

http.events["error"] = (client, error) -> println(error)
http.events["listen"] = (port) -> println("Listening on $port")
server = Server(http)

t = @async run(server, 3000)

This starts a simple little web server asynchronously. The problem is I have no idea how to stop it. I've been going through the Julia documentation and trying to find some function that will remove this task from the queue (kill, interrupt, etc.) but nothing seems to work.

How can I kill this task?

like image 615
Nick Avatar asked Nov 30 '14 03:11

Nick


1 Answers

I don't see an official way to end a task specifically, but I think the general solution was the addition of throwto, which allows you to immediately schedule a task with a pending exception.

...
t = @async run(server, 3000)
...
ex = InterruptException()
Base.throwto(t, ex)
close(http.sock) # ideally HttpServer would catch exception to cleanup
like image 96
lossleader Avatar answered Nov 11 '22 07:11

lossleader