multithreading - Python concurrent futures executor.submit timeout -


i want use many thread timeout thread. use following code :

import concurrent.futures  class action:      def __init(self):         self.name = 'initial'      def define_name(self):         # in real code method executed during 30-60 seconds         self.name = 'name'  action_list = [     action(),     action(), ]  concurrent.futures.threadpoolexecutor(     max_workers = 20 ) executor:     action_item in action_list:         # without timeout arg, works !         executor.submit(action_item.define_name, timeout=1)  action_item in action_list:     print(action_item.name) 

i seen post how use concurrent.futures timeouts? don't need use result method

python documentation don't me (https://docs.python.org/3/library/concurrent.futures.html). shows how define timeout map method not submit.

do know way define timeout executor.submit method ?

edit : example simple. in real case, have list of 15000+ items. each action run executor.submit() during 30 - 60 secondes. items action during more of 5 minutes, want execpt tiemout these items.

edit 2 : want stop thread after timeout. don't want use thread object. post (is there way kill thread in python?) don't resolve problem. want use concurrent.futures module.

if want async execution timeout, can pack future inside future last 1 can wait main future , whole thing non-blocking. this:

executor.submit(lambda: executor.submit(func, arg).result(timeout=50))

but quite sloppy , ineffective.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -