# SimJulia, interrupt() error

**URL:** <https://discourse.julialang.org/t/simjulia-interrupt-error/30571>\
**Category:** General Usage\
**Tags:** package\
**Created:** [November 1, 2019, 1:05am UTC](https://discourse.julialang.org/t/simjulia-interrupt-error/30571 "2019-11-01T01:05:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![zhangliye](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zhangliye/32/3208_2.png) [@zhangliye](https://discourse.julialang.org/u/zhangliye)\
**Post date:** [November 1, 2019, 1:05am UTC](https://discourse.julialang.org/t/simjulia-interrupt-error/30571/1 "2019-11-01T01:05:28Z")

</div>

When interrupt one process which have an event with callback function, an error occurs. The small example code is as follows.

```julia
function my_callback(ev::AbstractEvent, env::Environment)
  println("Called back from ", ev)
  println( "callback time: ", now(env) )
end

@resumable function charge(env::Environment, duration::Number)
    @yield timeout(env, duration)
end

@resumable function driver(env::Environment, car_process::Process)
    @yield timeout(env, 3)
    @yield interrupt(car_process)
end

@resumable function car(env::Environment)
  while true
    println("Start parking and charging at ", now(env))
    charge_duration = 5
    charge_process = @process charge(sim, charge_duration)
    @callback my_callback( charge_process, env ) # no error without this line

    try
      @yield charge_process
    catch e
      println("Was interrupted. Hopefully, the battery is full enough ...")
      #rethrow(e)
    end
    println("Start driving at ", now(env))
    trip_duration = 2
    @yield timeout(sim, trip_duration)
    println("Now: ", now(env))
  end
end

#####################################
sim = Simulation()

car_process = @process car(sim)
@process driver(sim, car_process)

run(sim, 15)

```

The error is as follows,

```julia
Start parking and charging at 0.0
ERROR: LoadError: LoadError: MethodError: no method matching iterate(::Nothing)
Closest candidates are:
  iterate(::Core.SimpleVector) at essentials.jl:568
  iterate(::Core.SimpleVector, ::Any) at essentials.jl:568
  iterate(::ExponentialBackOff) at error.jl:199
  ...
Stacktrace:
 [1] _deleteat!(::Array{Function,1}, ::Nothing) at ./array.jl:1217
 [2] deleteat!(::Array{Function,1}, ::Nothing) at ./array.jl:1212
 [3] remove_callback(::Function, ::Process) at /Users/zhangliye/.julia/packages/SimHPC/ljsCA/src/base.jl:63
 [4] execute_interrupt(::SimHPC.Interrupt, ::Process) at /Users/zhangliye/.julia/packages/SimHPC/ljsCA/src/processes.jl:53
 [5] (::getfield(SimHPC, Symbol("##3#4")){typeof(SimHPC.execute_interrupt),SimHPC.Interrupt,Tuple{Process}})() at /Users/zhangliye/.julia/packages/SimHPC/ljsCA/src/base.jl:51
 [6] step(::Simulation) at /Users/zhangliye/.julia/packages/SimHPC/ljsCA/src/simulations.jl:39
 [7] run(::Simulation, ::SimHPC.Timeout) at /Users/zhangliye/.julia/packages/SimHPC/ljsCA/src/base.jl:91
 [8] run(::Simulation, ::Int64) at /Users/zhangliye/.julia/packages/SimHPC/ljsCA/src/events.jl:29
 [9] top-level scope at none:0
 [10] include at ./boot.jl:326 [inlined]
 [11] include_relative(::Module, ::String) at ./loading.jl:1038
 [12] include(::Module, ::String) at ./sysimg.jl:29
 [13] include(::String) at ./client.jl:403
 [14] top-level scope at none:0
 [15] include at ./boot.jl:326 [inlined]
 [16] include_relative(::Module, ::String) at ./loading.jl:1038
 [17] include(::Module, ::String) at ./sysimg.jl:29
 [18] include(::String) at ./client.jl:403
 [19] top-level scope at none:0
in expression starting at /Users/zhangliye/julia_dev/LDTSim/test/test_lib.jl:134
in expression starting at /Users/zhangliye/julia_dev/LDTSim/test/runtests.jl:5
ERROR: Package LTDSim errored during testing

```

Julia version information is as follows,

```julia
Julia Version 1.1.0
Commit 80516ca202 (2019-01-21 21:24 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin14.5.0)
  CPU: Intel(R) Core(TM) i5-8500 CPU @ 3.00GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.1 (ORCJIT, skylake)
Environment:
  JULIA_NUM_THREADS = 6

```

---

<div class="post-metadata">

**Author:** ![hdavid16](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hdavid16/32/11531_2.png) [@hdavid16](https://discourse.julialang.org/u/hdavid16)\
**Post date:** [May 23, 2021, 1:49am UTC](https://discourse.julialang.org/t/simjulia-interrupt-error/30571/2 "2021-05-23T01:49:18Z")

</div>

Hi @zhangliye,

I ran into this same issue! I found a fix for it. The remove\_callback function needed to be improved as shown in this PR: [Make remove\_callback more robust by hdavid16 · Pull Request #72 · BenLauwens/SimJulia.jl · GitHub](https://github.com/BenLauwens/SimJulia.jl/pull/72)

Let me know if it works.
