In a Python project, I use ThreadPoolExecutor to multithreading my program. I use one thread by instance of object in order to run one method. At this time, I use this syntaxe :
class Fqdn():
def port_scan(self):
# Do a TCP scan
pass
# Used because I must submit a function with ThreadPoolExecutor
def port_scan(fqdn):
fqdn.port_scan()
with concurrent.futures.ThreadPoolExecutor(max_workers=THREAD_LIMIT) as executor:
# fqdn_list is a list of Fqdn instances
for fqdn in fqdn_list:
executor.submit(port_scan, fqdn)
Do you have any idea which lets me to submit an method instance to my executor ?
Pass the bound method, fqdn.port_scan
:
with concurrent.futures.ThreadPoolExecutor(max_workers=THREAD_LIMIT) as executor:
# fqdn_list is a list of Fqdn instances
for fqdn in fqdn_list:
executor.submit(fqdn.port_scan)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With