V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
v2gba
V2EX  ›  问与答

请教下这样的 python script 如何改成多线程

  •  
  •   v2gba · Oct 23, 2015 · 1540 views
    This topic created in 3838 days ago, the information mentioned may be changed or developed.

    大概的代码是:

    def get_info(user):
        children = get_children(user)
        add_to_file(user, children)
        for i in children:
            get_info(i)
    

    这个程序的瓶颈在于get_child()需要连接远程数据库获取,花费不少时间。

    假设数据库不会拒绝同一时间的多次访问,如何优化这个脚本?(这应该用多线程比较合适吧)

    2 replies    2015-10-24 00:05:55 +08:00
    emric
        1
    emric  
       Oct 24, 2015
    I/O 瓶颈应该用异步吧.
    gamexg
        2
    gamexg  
       Oct 24, 2015 via Android
    队列 线程池。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2972 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 00:29 · PVG 08:29 · LAX 17:29 · JFK 20:29
    ♥ Do have faith in what you're doing.