I'm running a threadpool executor to which I submit some tasks.
executor = ThreadPoolExecutor(thread_name_prefix='OMS.oms_thread_', max_workers=16)
task = executor.submit(method_to_run, args)
I know I can get the status of these by calling task.running() to know if it is completed or not. What I can't figure out is how to measure how much time a task spent waiting to be started. One way could be to store the time when a task was created, and pass some task Id to method_to_run and have it store the time when it started running and get the difference between those times.
But that's a lot of trouble and would need me to change the method_to_run. Is there a better way?
The main idea is to subclass the
Executor, overload thesubmitmethod in such a way to record the time before returning aFutureobject representing the task and make a customchrono_submit2runningwhich query theFutureobjects untilrunningisTrue.Output