python gevent:识别池中的哪个线程

时间:2018-04-18 14:11:37

标签: python-2.7 concurrency gevent

在池中运行gevents时,是否有办法识别池中哪个线程在给定时间运行?这对于记录非常有用。

例如:

from gevent.pool import Pool

def func(arg):
  pool_id = #some way to id the pool
  logger.debug("[{}] {}".format(pool_id, arg))

pool = Pool(10):
pool.map(func, range(50))

1 个答案:

答案 0 :(得分:0)

threading.current_thread()

threading.get_ident() for python> = 3.3。