How to timeout tokio_threadpool::blocking?


                      tokio_threadpool::blocking(|| {
                           print_message(&s, message_id); //lets assume that function can hang.
                       }).map_err(|_| panic!("the threadpool shut down"));

Above code blocks indefinitely, is there a way to timeout tokio_threadpool::blocking?

Thanks and regard

Unfortunately, no. Can I ask what is your closure inside blocking() doing? Perhaps there is an alternative solution that doesn’t involve interrupting blocking().

This might be a wild guess, but are you perhaps trying to do a blocking read from stdin? :slight_smile:

1 Like

In production code it might be doing one of the three possible things:

  1. Reading data from local disk or network.
  2. Waiting on a request from another server node.
  3. Long computation, which can get stuck.