V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
lbfeng
V2EX  ›  Python

ThreadPoolExecutor 执行没有参数的方法

  •  
  •   lbfeng · Dec 10, 2019 · 4102 views
    This topic created in 2335 days ago, the information mentioned may be changed or developed.
    def thread_function():
        logging.info("Thread %s: starting")
        time.sleep(2)
        logging.info("Thread %s: finishing")
    
    with concurrent.futures.ThreadPoolExecutor(3) as executor:
       executor.map(thread_function)
    

    如果 thread_function 没有参数的话,executor.map 是不是应该没有第二个参数.

    8 replies    2019-12-11 09:10:25 +08:00
    lbfeng
        2
    lbfeng  
    OP
       Dec 10, 2019
    @leonme 问之前就看了。。并没有提到 iterables 如果没有该怎么办
    lbfeng
        3
    lbfeng  
    OP
       Dec 10, 2019
    关于 threadpoolexecutor map parameter 的都是 multiple parameter 的问题,没有 no parameter。。。
    ClericPy
        4
    ClericPy  
       Dec 10, 2019
    该看的是 submit 得到 Future 后的用法吧

    map 又不是万能的, 实在无聊那就

    xx.map(lambda f: f(), [f])
    guokeke
        5
    guokeke  
       Dec 10, 2019
    wzwwzw
        6
    wzwwzw  
       Dec 10, 2019
    用 submit /
    lbfeng
        7
    lbfeng  
    OP
       Dec 10, 2019
    ```
    with concurrent.futures.ThreadPoolExecutor(3) as executor:
    future = executor.submit(thread_function_no_parameter)
    print(future.result())
    ```

    如果想启动 3 个 thread,需要重复 executor.submit(thread_function_no_parameter) 3 遍??
    wzwwzw
        8
    wzwwzw  
       Dec 11, 2019
    @lbfeng 看下官方 demo future_to_url = {executor.submit(load_url, url, 60): url for url in URLS} 循环。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2473 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 08:01 · PVG 16:01 · LAX 01:01 · JFK 04:01
    ♥ Do have faith in what you're doing.