把以下代码改为没有类的线程 class Cloud_oper(threading.Thread): def __init__(self,localpath): threading.Thread.__init__(self) self.localpath = localpath def run(self): last_send_time = 0 while True: now = datetime.now() current_time = now.strftime("%Y%m%d%H%M%S") filename = "time_{}.mp4".format(current_time) buzz = beep.get() now_time = time.time() if buzz == 1: if now_time - last_send_time >= 5: qiniu_test.qiniu_upload('./save') miao_note.send_note(filename) last_send_time = now_time # else:
时间: 2024-02-14 09:04:57 浏览: 181
RedHat_Linux安装Oracle10g
以下是修改后的代码,去掉了类的部分:
```python
import threading
from datetime import datetime
import time
import beep
import qiniu_test
import miao_note
def cloud_oper(localpath):
last_send_time = 0
while True:
now = datetime.now()
current_time = now.strftime("%Y%m%d%H%M%S")
filename = "time_{}.mp4".format(current_time)
buzz = beep.get()
now_time = time.time()
if buzz == 1:
if now_time - last_send_time >= 5:
qiniu_test.qiniu_upload(localpath)
miao_note.send_note(filename)
last_send_time = now_time
# else:
# do something else
```
在上面的代码中,我们把原来的`Cloud_oper`类改成了一个普通的函数`cloud_oper`,并把`__init__`方法和`run`方法合并成一个函数。然后我们在这个函数中执行了原来`run`方法中的所有操作,除了最后的`else`分支。
阅读全文