Reputation:
I am trying to run as many thread as possible. however I have problem here
C:\Python27\lib\threading.py
_start_new_thread(self.__bootstrap, ())
thread.error: can't start new thread
When I call this
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!"
I want to run as many thread as possible
Upvotes: 1
Views: 2469
Reputation: 434
Now assuming you want to add unlimited threads, you need functions to simply finish, this code never ends with threads -> your unlimited threads:
from threading import Thread
def sleeper(i):
print(i)
i = 0
while(1):
t = Thread(target=sleeper, args=(i,))
t.start()
i += 1
Upvotes: 0
Reputation: 434
There is a limit to how many threads you can start that the system can simultaneously handle, you need to either close these threads from within (by having the function you thread either finish or while loops break) or try joining the threads by creating a list of these threads and joining the list items.
list_of_threads.append(example)
example.start()
for thread in list_of_threads:
thread.join()
Upvotes: 1