# Killing long-running thread starting in a web server

**URL:** <https://discourse.julialang.org/t/killing-long-running-thread-starting-in-a-web-server/94128>\
**Category:** General Usage\
**Tags:** web, multithreading, api\
**Created:** [February 6, 2023, 9:46am UTC](https://discourse.julialang.org/t/killing-long-running-thread-starting-in-a-web-server/94128 "2023-02-06T09:46:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cjproud](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjproud/32/38494_2.png) [@cjproud](https://discourse.julialang.org/u/cjproud)\
**Post date:** [February 6, 2023, 9:46am UTC](https://discourse.julialang.org/t/killing-long-running-thread-starting-in-a-web-server/94128/1 "2023-02-06T09:46:41Z")

</div>

I’m trying to use [Oxygen.jl](https://github.com/ndortega/Oxygen.jl) as an API for a long running `ccall`. I’m trying to create a toy example where, after 30 seconds, the solver task called by `call_solver()` on a new thread is passed `InterruptException` and stops. The way I’m attempting this is having a polling function called `check_solver()` on a separate thread which schedules the exception after 30 seconds.

```julia
    function check_solver(t)  
      time = 0
      timeout = 30
      while time < timeout
        sleep(1)
        time +=1 
        println("Current time is $time")
      end
        schedule(t,InterruptException();error = true)
    end

    t = Threads.@spawn call_solver()
    wait(Threads.@spawn check_solver(t))

```

this doesn’t appear to work on the `ccall` runs to completion. I’ve also tried something simple like:

```julia
  t = Threads.@spawn call_solver()
  sleep(10)
  schedule(t,InterruptException();error = true)

```

and this also doesn’t work. I have a feeling that either the `ccall` switches threads on interruption or the `schedule` never gets called as the `ccall` is continually using the thread.

Thanks for your help, I’m a bit stumped!

---

<div class="post-metadata">

**Author:** ![cjproud](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjproud/32/38494_2.png) [@cjproud](https://discourse.julialang.org/u/cjproud)\
**Post date:** [February 6, 2023, 9:54am UTC](https://discourse.julialang.org/t/killing-long-running-thread-starting-in-a-web-server/94128/2 "2023-02-06T09:54:27Z")

</div>

I’ve tried watching `htop` during the execution and I’ve noticed that before running `schedule(t,InterruptException();error = true)` I can see it’s only running on a single thread:

 ![Screenshot 2023-02-06 at 5.51.22 pm](https://global.discourse-cdn.com/julialang/original/3X/a/5/a5504ad2113bf0c65ba5c4003918f71736f823ad.png)

but after running `schedule(t,InterruptException();error = true)` multiple times I can see that the other threads start seeing increased loads:

 ![Screenshot 2023-02-06 at 5.51.52 pm](https://global.discourse-cdn.com/julialang/original/3X/2/3/23772e5b37161fafef92e0024dffe7a9853ac0ee.png)
