Skip to content Skip to sidebar Skip to footer

First Time Attempting To Thread Using Concurrent.futures-why Do I Get No Output?

I'm very new to python, so there could be multiple things wrong with my code. But I can't debug because I literally get no output, including no error. Would love some help. I'm in

Solution 1:

You were mapping a tuple with two values to the function. On each mapping it was sending a single argument, but your function takes two arguements comic_start and comic_end

To see this, you could take out your other arguement and do:

defsimple_function(first_arg):
    print(first_arg)

with cf.ThreadPoolExecutor(max_workers=10) as executor:
     executor.map(simple_function, (1, 100))

Result:

1
100

Modified Code:

import concurrent.futures as cf

defsimple_function(_range):

    #fill with driver stuff etcfor num in _range:
        print('Downloading page http://xkcd.com/%s...' % (num))       

_max = 200#max range you want
workers = 10with cf.ThreadPoolExecutor(max_workers=workers) as e:

    cs= _max // workers #chunksize to split across threads#we chunk the range to be split across the threads so you can iterate#over the chunked range in the mapped function.#x + cs if x + cs <= _max else _max next upper bound by chunksize but #we don't want to exceed the maximum range you want, so we default to _max#if the next upper bound exceeds this#x - 1 if x!= 0 else x, start initial range at 0, and last upper#bound is exclusive so x - 1 if were not at the initial range.
    ranges = [range(x - 1if x != 0else x, x + cs if x + cs <= _maxelse _max) 
              for x inrange(0, _max, cs)]

    e.map(simple_function, ranges)

Post a Comment for "First Time Attempting To Thread Using Concurrent.futures-why Do I Get No Output?"