python 查看add_done_callback函数的运行线程

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 查看add_done_callback函数的运行线程相关的知识,希望对你有一定的参考价值。

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import threading
import sys
import time

from concurrent.futures import ThreadPoolExecutor


executor = ThreadPoolExecutor()

def wait_on_future():
    print("[{}]: thread id is {}".format(sys._getframe(0).f_code.co_name,
                                         threading.current_thread().ident))
    time.sleep(5)
    return pow(5, 22)


def get_thread_id(future):
    print("[{}]: thread id is {}".format(sys._getframe(0).f_code.co_name,
                                         threading.current_thread().ident))


def main():
    print("[{}]: thread id is {}".format(sys._getframe(0).f_code.co_name,
                                         threading.current_thread().ident))
    f = executor.submit(wait_on_future)
    f.add_done_callback(get_thread_id)

if __name__ == '__main__':
    main()

以上是关于python 查看add_done_callback函数的运行线程的主要内容,如果未能解决你的问题,请参考以下文章