第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Python 中線(xiàn)程部分的代碼實(shí)踐求教 主要是類(lèi)的

Python 中線(xiàn)程部分的代碼實(shí)踐求教 主要是類(lèi)的

22with33 2018-09-21 20:22:26
import?math import?time from?threading?import?Thread class?SquareRootCaluatotor: ????"""This?class?spawn?a?separate?thread?to?calculate?a?bunch?of?square?roots?,and?checks?in?it?once?a?second?until?it?finishes""" ????def?__init__(self,target): ????????"""Turn?on?the?calculator?thread?and,while?waiting?for?it?to?finish,periodically?monitor?its?progress""" ????????self.result?=?[] ????????counter?=?self.CalculatorThread(self,target) ????????print("Turning?on?the?calculator?thread") ????????counter.start() ????????while?len(self.result)<target: ????????????print("%d?square?roots?calculated?so?far."?%len(self.result)) ????????????time.sleep(1) ????????print("calculated?%s?square?root;the?last?one?is?sqrt(%d)=%f"?%(target,len(self.results),self.result.results[-1])) class?CalculatorThread(Thread): ????"""A?separate?thread?which?actually?does?the?calculations.""" ????def?__init__(self,controller,target): ????????"""Set?up?this?thread,including?makeing?it?a?daemon?thread?so?that?the?script?can ????????end?without?waiting?for?this?thread?to?finish""" ????????Thread.__init__(self) ????????self.controller?=?controller ????????self.target?=?target ????????self.setDaemon(True) ????def?run(self): ????????"""Calculate?square?roots?for?all?numbers?between?1?and?the?target,?inclusive.""" ????????for?i?in?range(1,self.target+1): ????????????self.controller.results.append(math.sqrt(i)) ????if?__name__?==?'main': ????????import?sys ????????limit?=?None ????????if?len(sys.argv)?>1: ????????????limit?=?sys.argv[1] ????????????try: ????????????????limit?=?int(limit) ????????????except?ValueError: ????????????????print("Usage:%s?[number?of?square?roots?to?calculate" ????????????????%?sys.argv[0]) ????????SquareRootCaluatotor(limit)求教:1在給SquareRootCaluatotor類(lèi)實(shí)例后運(yùn)行,總是提示無(wú)CalculatorThread屬性,請(qǐng)問(wèn)這是為什么?????????????2 這個(gè)文件的正確運(yùn)行步驟是什么?我給SquareRootCaluatotor賦變量運(yùn)行是否正確?
查看完整描述

2 回答

  • 2 回答
  • 0 關(guān)注
  • 962 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)