Skip to content

ThreadPoolExecutor#kill: documentation and implementation are out of sync #1072

Open
@hms

Description

@hms
* Operating system:                mac
* Ruby implementation:             Ruby
* `concurrent-ruby` version:       1.3.4
* `concurrent-ruby-ext` installed: no
* `concurrent-ruby-edge` used:     no

The docs for ThreadPoolExecutor#kill suggest that inflight tasks will run to completion.

#kill

Begin an immediate shutdown. In-progress tasks will be allowed to complete but enqueued tasks will be dismissed and no new tasks will be accepted. Has no additional effect if the thread pool is not running.

This (maybe too) simple test suggests the Executor will kill its internal threads and not allow them to finish.

e = Concurrent::ThreadPoolExecutor.new
f = Concurrent::Promises.future_on(e) { sleep 10; puts "I'm alive!" }
sleep 11
I'm alive!
f = Concurrent::Promises.future_on(e) { sleep 10; puts "I'm alive!" }
e.kill
e.shutdown? => true
# future f never completes

The code for #kill in ruby_executor_service.rb:

def kill
  synchronize do
     break if shutdown?
     stop_event.set
     ns_kill_execution 
     stopped_event.set
   end
   true
 end

ns_kill_execution:

def ns_kill_execution
 # TODO log out unprocessed tasks in queue
 # TODO try to shutdown first?
 @pool.each(&:kill)
 @pool.clear
 @ready.clear
end

and @pool.each(&:kill) concludes with:

def kill
  @thread.kill
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions