V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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
gancl
V2EX  ›  Python

python executor.submit(my_function, i) 偶尔不执行怎么办?

  •  
  •   gancl · 2016-01-01 14:50:24 +08:00 · 3558 次点击
    这是一个创建于 3035 天前的主题,其中的信息可能已经有所发展或是发生改变。

    executor.submit(my_function, i) 为什么运行了一段时间, my_function 函数就会偶尔不执行

    MAX_THREAD=100
    executor = concurrent.futures.ThreadPoolExecutor(max_workers=MAX_THREAD)
    def startTheadCancel(self,orderIds):
    #t = Thread(target=orderCancelStart, args=(self,orderIds))
    #t.start()
    executor.submit(orderCancelStart,self,orderIds)

    就是像这样的, 用自己创建线程就都会执行

    用 executor.submit ,有时就没执行,几十分钟出现一次

    一秒钟不同的地方可能会 executor.submit 多次,因为交易软件非常频繁地创建线程,一秒钟创建 n 个,花销在创建和销毁线程的时间会很多,所以想用 executor ,但是 executor 却会出现有时执行不到函数里的情况。

    1 条回复    2016-01-01 15:15:55 +08:00
    gancl
        1
    gancl  
    OP
       2016-01-01 15:15:55 +08:00
    现在发现自己创建线程,偶尔也是会没执行到。只是机率没那么高,一两个小时才出现吧
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1712 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 16:41 · PVG 00:41 · LAX 09:41 · JFK 12:41
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.