M
M
Maxim Zubenko2019-09-10 16:32:00
Python
Maxim Zubenko, 2019-09-10 16:32:00

How to multithread, using executor.map, pass many parameters to the function, and iterate one?

There is a brute function (code enumeration) that starts iteration by a separate function

def checkCode(session, code, code_for_url, referer):
    pass

def bruteCode(s, url_code, referer):
    start_code = 110000
    end_code = 111000

     for code in range(start_code, end_code + 1):
            s, success = checkCode(s, code, url_code, referer)  # проверяем код
            if success:
                return code

I am reading this article , where I want to take this example as a basis:
from concurrent.futures import ThreadPoolExecutor

with ThreadPoolExecutor(concurrency) as executor:
    for _ in executor.map(upload, queryset):
        pass

and I can't figure out how I can change my for to run checkCode multi-threaded.
let's say:
worker = 10
    with ThreadPoolExecutor(worker) as executor:
        # и дальше затык. 
        # 1. Как мне передать в executor.map свою checkCode c кучей параметров, 
        # но где будет постоянно меняться параметр code
        # 2. Как мне указать диапазон?
        # 3. В примере стоит в цикле pass, мне тоже нужно писать pass?
        for code in range(start_code, end_code + 1):
            s, success = checkCode(s, code, url_code, referer)  # проверяем код
            if success:
                return code

Sincerely.
ps some yields are spinning in my head, but I never used them, but only once read in passing and did not really understand the application. If they are needed, then write an example please . (if there is no example, then it is better not to write anything)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Kitaev, 2019-09-10
@JawsIk

functools.partial

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question