runtimeerror: thread.__init__() not called
时间: 2023-05-08 10:58:00 浏览: 95
这个错误通常出现在多线程编程中。它表示在创建线程对象时,没有正确地调用构造函数(__init__()函数)。线程对象是基于Python中的Thread类创建的,该类具有许多可用于创建和管理线程的方法和属性,包括__init__()。
正确创建一个线程对象的方法是在创建对象时使用类的构造函数并将所有必要的参数传递给它。例如,如果您想创建一个名为“my_thread”的线程对象,并且您希望该线程使用“run_function”函数作为其主要功能,则应编写以下代码:
my_thread = threading.Thread(target=run_function)
其中“target”参数指定主要功能,该功能将在新线程中启动并运行。如果您在创建线程对象时省略了“target”参数,则可能会收到“runtimeerror: thread.__init__() not called”错误。
因此,要消除此错误,请确保您在创建线程对象时正确调用Thread类的构造函数,并确保所有必要的参数均被正确传递。
相关问题
RuntimeError: '__init__' method of object's base class (Feed) not called.
这个错误通常是因为你定义的类没有正确地调用其父类的构造函数。确保在你的类的构造函数中调用父类的构造函数,例如:
```python
class MyFeed(Feed):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# your code here
```
或者,如果你在 Python 2 中工作,可以使用旧式的语法:
```python
class MyFeed(Feed):
def __init__(self, *args, **kwargs):
super(MyFeed, self).__init__(*args, **kwargs)
# your code here
```
这样就能够正确地调用父类的构造函数,避免了这个错误。
RuntimeError: "clamp_scalar_cpu" not implemented for 'Half'
这个错误通常是因为在代码中没有正确地初始化线程对象导致的。在给出的代码中,错误信息指出在"thread.__init__()"方法没有被调用。这可能是因为该方法没有被正确地调用或者在子类的构造函数中没有调用父类的构造函数。可以尝试在"NotifyThread"类的构造函数中添加"threading.Thread.__init__(self)"来正确地初始化线程对象。这样做应该能够解决这个RuntimeError。<span class="em">1</span>
#### 引用[.reference_title]
- *1* [Python RuntimeError: thread.__init__() not called解决方法](https://download.csdn.net/download/weixin_38705004/13773485)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"]
[ .reference_list ]