python创建子类_Python线程创建子类?
當我在python中使用線程時,我在思考創建子類的原因時遇到了一個問題。我看過很多網站,包括tutorialspoint。在
文檔說您需要定義Thread類的一個新子類。我對類有一個基本的了解,但根本沒有玩過子類。我還沒有用過像os&ftplib這樣的模塊。有誰能給我指出一個網站,可以更好地解釋這一點的新手腳本?在#!/usr/bin/python
import threading
class myThread (threading.Thread):
我可以在不創建這個子類的情況下編寫我自己的腳本,它可以工作,所以我不確定為什么這是一個要求。這是我創建的一個簡單的小腳本,用來幫助我理解線程。在
^{pr2}$
謝謝你的幫助!在
我用tutorialspoint.com作為我的參考資料。聽上去你說我吃得太多了,考慮到我還不需要使用更復雜的選項,我現在應該保持簡單。網站上是這么說的:Creating Thread using Threading Module:
To implement a new thread using the threading module, you have to do the following:
- Define a new subclass of the Thread class.
- Override the __init__(self [,args]) method to add additional arguments.
- Then, override the run(self [,args]) method to implement what the thread should do when started.
Once you have created the new Thread subclass, you can create an instance of it and then start a new thread by invoking the start(), which will in turn call run() method.
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的python创建子类_Python线程创建子类?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java 搜索文件 pdf_Java查找
- 下一篇: java 类的重载_Java自学-类和对