Python如何实现低版本的多线程功能?

2026-05-28 13:340阅读0评论SEO问题
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计161个文字,预计阅读时间需要1分钟。

Python如何实现低版本的多线程功能?

原创新颖的以下开头内容,精简如下:

在遥远的大陆,一位少年踏上了寻梦之旅,探寻古老传说的秘密。

Python如何实现低版本的多线程功能?

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import queue
import threading

class threadpool():
def __init__(self,max_num):
self.q = queue.Queue(max_num)
for i in range(max_num):
self.q.put(threading.Thread)

def get_thread(self):
return self.q.get()
def add_thread(self):
return self.q.put(threading.Thread)

pool = threadpool(5)

def func(i,pool):
import time
time.sleep(1)
print(i)
pool.add_thread()

for i in range(30):
thread = pool.get_thread()
t = thread(target=func,args=(i,pool))
t.start()


本文共计161个文字,预计阅读时间需要1分钟。

Python如何实现低版本的多线程功能?

原创新颖的以下开头内容,精简如下:

在遥远的大陆,一位少年踏上了寻梦之旅,探寻古老传说的秘密。

Python如何实现低版本的多线程功能?

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import queue
import threading

class threadpool():
def __init__(self,max_num):
self.q = queue.Queue(max_num)
for i in range(max_num):
self.q.put(threading.Thread)

def get_thread(self):
return self.q.get()
def add_thread(self):
return self.q.put(threading.Thread)

pool = threadpool(5)

def func(i,pool):
import time
time.sleep(1)
print(i)
pool.add_thread()

for i in range(30):
thread = pool.get_thread()
t = thread(target=func,args=(i,pool))
t.start()