带期货的Python多线程-如何获取工作者ID?

带期货的Python多线程-如何获取工作者ID?,python,Python,我有一份工作清单,比如说要处理100个项目。我想运行2个工作线程来处理它们。每个线程都有自己的资源,在变量x中。我现在的问题是我不确定如何访问变量x。我需要确定我是工人0还是工人1。如果我是worker 0,我使用x[0]否则我使用x[1] x = [] x[0] = ... x[1] = ... def f(job): # How to access variable x? I need to know if I'm worker 0 or worker 1 i = ???

我有一份工作清单,比如说要处理100个项目。我想运行2个工作线程来处理它们。每个线程都有自己的资源,在变量
x
中。我现在的问题是我不确定如何访问变量
x
。我需要确定我是工人0还是工人1。如果我是worker 0,我使用
x[0]
否则我使用
x[1]

x = []
x[0] = ...
x[1] = ...

def f(job):
    # How to access variable x? I need to know if I'm worker 0 or worker 1
    i = ???
    x[i].process(job)

with concurrent.futures.ThreadPoolExecutor(max_workers=2) as e:
    jobs = ...
    assert(len(jobs) == 100)
    return list(e.map(f))