最好的线程池包。

vthread的Python项目详细描述


您可以通过添加一行代码来实现线程池,而无需更改任何先前代码的顺序。

importvthread@vthread.pool(3)# just use this line to make pool, Create a threadpool with three threadsdefcrawl(i):importtime;time.sleep(1)# Simulation time consumingprint("crawl_url:",i)urls=["http://url1","http://url2","http://url3","http://url4"]foruinurls:crawl(u)# This function becomes a function that adds the original function to the thread pool.

它提供了对线程池进行分组的方法

importvthreadpool_1=vthread.pool(5,gqueue=1)# open a threadpool with 5 threads named 1pool_2=vthread.pool(2,gqueue=2)# open a threadpool with 2 threads named 2@pool_1deffoolfunc1(num):time.sleep(1)print(f"foolstring1, test3 foolnumb1:{num}")@pool_2deffoolfunc2(num):time.sleep(1)print(f"foolstring2, test3 foolnumb2:{num}")@pool_2deffoolfunc3(num):time.sleep(1)print(f"foolstring3, test3 foolnumb3:{num}")foriinrange(10):foolfunc1(i)foriinrange(4):foolfunc2(i)foriinrange(2):foolfunc3(i)# default gqueue is 0

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java将字符串拆分为带关键字的部分   删除数据库后未指定java数据源问题“url”属性   网络化java多人游戏连接   Java当新字符串等于旧字符串时,为什么substring()不创建新对象?   一个实例到多个bean的java注入   JavaSpringMVC验证错误消息   java总结if语句,并从另一个对象(如字符串[])读取if条件(动态if)   需要多个输入的Java IF语句   jsf如何选择正确的bean范围?   java将数据库值加载到组合框JSP,Hibernate   一次活动中的java 3布局   团队和球员反对Java的困难   java ActionListener如何知道按下了哪个按钮?