将函数作为参数传递会删除对self的正确引用?

时间:2018-12-05 00:04:42

标签: python python-3.x concurrent.futures

我在python 3.6中使用concurrent.futures有这段代码:

with concurrent.futures.ProcessPoolExecutor(max_workers=MAX_WORKERS_ALLOWED) as executor:
        for file in executor.map(self.upload_chunked_part, chunk_list):
            total = total + file
            elapsed_time = round(time.time() - start_time, 2)
            current_speed = round(total / (elapsed_time * 1024 * 1024), 2)
            progress_bar("Uploading %s at %sMB/s" %
                         (media.name, current_speed), total, size)

// Each loop returns "Login required to API"

self.upload_chunked_part指的是与此代码所在的类关联的方法。当futures调用该方法时,self的实例将显示在被调用的对象中。如果我正常调用该方法,则代码与显示的代码不同:

self.upload_chunked_part(chunk) // Returns "Successful"

我希望我已经很好地解释了这个问题。关于如何进行这项工作的任何想法?

0 个答案:

没有答案