python创建子类_Python线程创建子类?
當(dāng)我在python中使用線程時(shí),我在思考創(chuàng)建子類的原因時(shí)遇到了一個(gè)問題。我看過很多網(wǎng)站,包括tutorialspoint。在
文檔說(shuō)您需要定義Thread類的一個(gè)新子類。我對(duì)類有一個(gè)基本的了解,但根本沒有玩過子類。我還沒有用過像os&ftplib這樣的模塊。有誰(shuí)能給我指出一個(gè)網(wǎng)站,可以更好地解釋這一點(diǎn)的新手腳本?在#!/usr/bin/python
import threading
class myThread (threading.Thread):
我可以在不創(chuàng)建這個(gè)子類的情況下編寫我自己的腳本,它可以工作,所以我不確定為什么這是一個(gè)要求。這是我創(chuàng)建的一個(gè)簡(jiǎn)單的小腳本,用來(lái)幫助我理解線程。在
^{pr2}$
謝謝你的幫助!在
我用tutorialspoint.com作為我的參考資料。聽上去你說(shuō)我吃得太多了,考慮到我還不需要使用更復(fù)雜的選項(xiàng),我現(xiàn)在應(yīng)該保持簡(jiǎn)單。網(wǎng)站上是這么說(shuō)的: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.
《新程序員》:云原生和全面數(shù)字化實(shí)踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀總結(jié)
以上是生活随笔為你收集整理的python创建子类_Python线程创建子类?的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java 搜索文件 pdf_Java查找
- 下一篇: java 类的重载_Java自学-类和对