线程错误无法启动新线程

时间:2017-08-12 05:19:38

标签: python

我正在尝试尽可能多地运行线程。不过我这里有问题

C:\Python27\lib\threading.py
  _start_new_thread(self.__bootstrap, ())
thread.error: can't start new thread

当我打电话给你时

  

class startSleep(threading.Thread):

import threading
import time

class startSleep(threading.Thread):
    def run(self):

        current = x 

# input of the treads
thread = input("Threads: ")

nload = 1

x = 0

# Threads
for x in xrange(thread):
    startSleep().start()
    time.sleep(0.003)
    print bcolors.BLUE + "Thread " + str(x) + " started!"

我想尽可能多地运行

2 个答案:

答案 0 :(得分:1)

系统可以同时处理多少个线程是有限的,你需要从内部关闭这些线程(通过让线程完成或者循环中断​​的函数)或者尝试通过以下方式连接线程:创建这些线程的列表并加入列表项。

list_of_threads.append(example)
example.start()
for thread in list_of_threads:
      thread.join()

答案 1 :(得分:0)

现在假设你想添加无限的线程,你需要简单完成的功能,这个代码永远不会以线程结束 - >你无限的线程:

from threading import Thread

def sleeper(i):
    print(i)

i = 0

while(1):
    t = Thread(target=sleeper, args=(i,))
    t.start()
    i += 1
相关问题