Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python线程名称不断增加(self.name-1,2,3…)_Python_Multithreading - Fatal编程技术网

Python线程名称不断增加(self.name-1,2,3…)

Python线程名称不断增加(self.name-1,2,3…),python,multithreading,Python,Multithreading,我在循环中使用Python中的线程。每5分钟它将创建线程并完成。 我正在记录线程名称,它似乎在增加 假设它运行了两个小时,线程名变为200,它是否会导致诸如不清除线程内存之类的问题?或者这不是问题?每个新线程都会获得一个新的、唯一的标识(名称)。已过时线程的标识将不会被重用 此外,您不能启动无限量的并发运行线程。这个例子最终会失败: import time import threading,thread class MyThread(threading.Thread): def run

我在循环中使用Python中的线程。每5分钟它将创建线程并完成。 我正在记录线程名称,它似乎在增加


假设它运行了两个小时,线程名变为200,它是否会导致诸如不清除线程内存之类的问题?或者这不是问题?

每个新线程都会获得一个新的、唯一的标识(名称)。已过时线程的标识将不会被重用

此外,您不能启动无限量的并发运行线程。这个例子最终会失败:

import time
import threading,thread

class MyThread(threading.Thread):
    def run(self):
        for _ in range(10):
            #print "I am %s" % self.getName()
            time.sleep(0.01)

if __name__ == "__main__":
    count = 1
    while True:
        print "Starting thread #%d..." % count
        MyThread().start()
        count += 1
如果添加一些错误处理,您将看到,一旦一个“旧”线程完成,就可以启动一个新线程

import time
import threading,thread

class MyThread(threading.Thread):
    def run(self):
        for _ in range(10):
            #print "I am %s" % self.getName()
            time.sleep(0.01)

if __name__ == "__main__":
    count = 1
    while True:
        try:
            print "Starting thread #%d..." % count
            MyThread().start()
            count += 1
        except thread.error:
            time.sleep(0.05)

每个新线程都会获得一个新的、唯一的标识(名称)。已过时线程的标识将不会被重用

此外,您不能启动无限量的并发运行线程。这个例子最终会失败:

import time
import threading,thread

class MyThread(threading.Thread):
    def run(self):
        for _ in range(10):
            #print "I am %s" % self.getName()
            time.sleep(0.01)

if __name__ == "__main__":
    count = 1
    while True:
        print "Starting thread #%d..." % count
        MyThread().start()
        count += 1
如果添加一些错误处理,您将看到,一旦一个“旧”线程完成,就可以启动一个新线程

import time
import threading,thread

class MyThread(threading.Thread):
    def run(self):
        for _ in range(10):
            #print "I am %s" % self.getName()
            time.sleep(0.01)

if __name__ == "__main__":
    count = 1
    while True:
        try:
            print "Starting thread #%d..." % count
            MyThread().start()
            count += 1
        except thread.error:
            time.sleep(0.05)

每个新线程都会获得一个新的、唯一的标识(名称)。已过时线程的标识将不会被重用

此外,您不能启动无限量的并发运行线程。这个例子最终会失败:

import time
import threading,thread

class MyThread(threading.Thread):
    def run(self):
        for _ in range(10):
            #print "I am %s" % self.getName()
            time.sleep(0.01)

if __name__ == "__main__":
    count = 1
    while True:
        print "Starting thread #%d..." % count
        MyThread().start()
        count += 1
如果添加一些错误处理,您将看到,一旦一个“旧”线程完成,就可以启动一个新线程

import time
import threading,thread

class MyThread(threading.Thread):
    def run(self):
        for _ in range(10):
            #print "I am %s" % self.getName()
            time.sleep(0.01)

if __name__ == "__main__":
    count = 1
    while True:
        try:
            print "Starting thread #%d..." % count
            MyThread().start()
            count += 1
        except thread.error:
            time.sleep(0.05)

每个新线程都会获得一个新的、唯一的标识(名称)。已过时线程的标识将不会被重用

此外,您不能启动无限量的并发运行线程。这个例子最终会失败:

import time
import threading,thread

class MyThread(threading.Thread):
    def run(self):
        for _ in range(10):
            #print "I am %s" % self.getName()
            time.sleep(0.01)

if __name__ == "__main__":
    count = 1
    while True:
        print "Starting thread #%d..." % count
        MyThread().start()
        count += 1
如果添加一些错误处理,您将看到,一旦一个“旧”线程完成,就可以启动一个新线程

import time
import threading,thread

class MyThread(threading.Thread):
    def run(self):
        for _ in range(10):
            #print "I am %s" % self.getName()
            time.sleep(0.01)

if __name__ == "__main__":
    count = 1
    while True:
        try:
            print "Starting thread #%d..." % count
            MyThread().start()
            count += 1
        except thread.error:
            time.sleep(0.05)
如果你愿意,你可以自己动手。如果不提供名称,Python将为您插入
Thread-N
,其中
N
是一个递增的整数

从引用的文档中:

类threading.Thread(group=None,target=None,name=None,args=(),kwargs={})

name是线程名称。默认情况下,一个唯一的名称由 形式“Thread-N”,其中N是一个小的十进制数

你可能不必为此担心。

如果你愿意,你可以自己去做。如果不提供名称,Python将为您插入
Thread-N
,其中
N
是一个递增的整数

从引用的文档中:

类threading.Thread(group=None,target=None,name=None,args=(),kwargs={})

name是线程名称。默认情况下,一个唯一的名称由 形式“Thread-N”,其中N是一个小的十进制数

你可能不必为此担心。

如果你愿意,你可以自己去做。如果不提供名称,Python将为您插入
Thread-N
,其中
N
是一个递增的整数

从引用的文档中:

类threading.Thread(group=None,target=None,name=None,args=(),kwargs={})

name是线程名称。默认情况下,一个唯一的名称由 形式“Thread-N”,其中N是一个小的十进制数

你可能不必为此担心。

如果你愿意,你可以自己去做。如果不提供名称,Python将为您插入
Thread-N
,其中
N
是一个递增的整数

从引用的文档中:

类threading.Thread(group=None,target=None,name=None,args=(),kwargs={})

name是线程名称。默认情况下,一个唯一的名称由 形式“Thread-N”,其中N是一个小的十进制数


你可能不必担心。

谢谢csl..我担心的是一个名字..现在解除了感谢csl..我担心的是一个名字..现在解除了感谢csl..我担心的是一个名字..现在解除了感谢csl..我担心的是一个名字..现在解除了