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

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

我怎樣才能有一個(gè)每秒更新一次的實(shí)時(shí)計(jì)時(shí)器來(lái)查看我的程序運(yùn)行了多少?

我怎樣才能有一個(gè)每秒更新一次的實(shí)時(shí)計(jì)時(shí)器來(lái)查看我的程序運(yùn)行了多少?

有沒(méi)有辦法制作一個(gè)每秒更新一次的計(jì)時(shí)器,這樣我就可以看到我的程序運(yùn)行了多長(zhǎng)時(shí)間。我嘗試制作一個(gè)循環(huán):i = 0for i in range(1000000):    i += 1    time.sleep(1)然后我想將其打印到我的discord.py 機(jī)器人中。它是這樣的:async def on_ready():    os.system('cls')    print('', fg('red'))    print(' _____ _                         ', fg('red'))    print('|  ___| | __ _ _ __  _ __  _   _ ', fg('red'))    print("| |_  | |/ _` | '_ \| '_ \| | | |", fg('red'))    print('|  _| | | (_| | |_) | |_) | |_| |', fg('red'))    print('|_|   |_|\__,_| .__/| .__/ \__, |', fg('red'))    print('              |_|   |_|     |___/ ', fg('red'))    print(f'Up-Time: {i}')    print(f'Version: {version}', fg('blue'))    print('~~~~~~~~~~~~~~~~~~~~~~~~~~~~', fg('green'))    print('[Server]: The Bot is online.', fg('green'))“Up-Time”是我想要顯示時(shí)間的地方,但是當(dāng)我嘗試運(yùn)行它時(shí),什么也沒(méi)有顯示。但是當(dāng)我將 print(i) 放在循環(huán)下面時(shí),它唯一做的就是打印出數(shù)字,而不運(yùn)行實(shí)際的服務(wù)器。如果解釋不夠好,我很抱歉,我對(duì) StackOverFlow 和一般編程非常陌生。抱歉,如果打擾您,先謝謝您!
查看完整描述

2 回答

?
ABOUTYOU

TA貢獻(xiàn)1812條經(jīng)驗(yàn) 獲得超5個(gè)贊

您可以通過(guò)多線程來(lái)完成此任務(wù)。您讓函數(shù)與您的時(shí)間一起運(yùn)行,并且函數(shù)運(yùn)行完畢后兩者都會(huì)立即終止:


import threading 

import time 


def calc(): #this function generates the square of all numbers between 1 and 56000000

    for i in range(1,56000000):

    i*i


t1 = threading.Thread(target=calc) 

t1.start() #starting a thread with the calc function

i = 1

while t1.is_alive(): #Check if the thread is alive

    time.sleep(1)# print time after every second

    print(f'Time elapsed ----------- {i}s')

    i = i+1

t1.join() #terminate thread once calc function is done 

print('Done!')


查看完整回答
反對(duì) 回復(fù) 2023-06-27
?
RISEBY

TA貢獻(xiàn)1856條經(jīng)驗(yàn) 獲得超5個(gè)贊

您永遠(yuǎn)不應(yīng)該使用time.sleepwithdiscord.py因?yàn)樗鼤?huì)停止您應(yīng)該使用的整個(gè)機(jī)器人await asyncio.sleep(1)。


您也可以創(chuàng)建此命令。


import datetime as dt


bot.launch_time = dt.datetime.utcnow()



@bot.command()

async def uptime(ctx):

    delta_uptime = dt.datetime.utcnow() - bot.launch_time

    hours, remainder = divmod(int(delta_uptime.total_seconds()), 3600)

    minutes, seconds = divmod(remainder, 60)

    days, hours = divmod(hours, 24)

    await ctx.send(f"{days}d, {hours}h, {minutes}m, {seconds}s")

現(xiàn)在您可以使用{prefix}uptime它來(lái)了解它已經(jīng)運(yùn)行了多長(zhǎng)時(shí)間。


查看完整回答
反對(duì) 回復(fù) 2023-06-27
  • 2 回答
  • 0 關(guān)注
  • 185 瀏覽
慕課專(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)