Python 3.x 如何使用PyQT5编写非阻塞代码,以便使用PyDrive上载到google drive?

Python 3.x 如何使用PyQT5编写非阻塞代码,以便使用PyDrive上载到google drive?,python-3.x,pyqt,pyqt5,pydrive,Python 3.x,Pyqt,Pyqt5,Pydrive,我试图上传数据到谷歌驱动器使用pydrive点击PyQT5按钮。我想在状态栏(或标签上)显示一条类似“正在备份数据…”的消息 然而,我只有在上传完成后才收到消息。pydrive上载进程似乎会阻止PyQT进程,直到上载完成 如何实现在上传过程中显示消息。下面是我的代码: def __init__(self, *args, **kwargs): super(HomeScreen,self).__init__() loadUi('uiScreens/HomeScreen.ui',sel

我试图上传数据到谷歌驱动器使用pydrive点击PyQT5按钮。我想在状态栏(或标签上)显示一条类似“正在备份数据…”的消息

然而,我只有在上传完成后才收到消息。pydrive上载进程似乎会阻止PyQT进程,直到上载完成

如何实现在上传过程中显示消息。下面是我的代码:

def __init__(self, *args, **kwargs):
    super(HomeScreen,self).__init__()
    loadUi('uiScreens/HomeScreen.ui',self)
    self.pushButton.clicked.connect(self.doDataBackup)

def doDataBackup(self):
    dbfile = "mumop.db"     #File to upload
    self.statusBar().showMessage("Data back up in progress....") # This is blocked by pydrive
    print("Data backup is in progress.....")  # This test line is not blocked by pdrive
    upload.uploadToGoogleDrive(dbfile))
    
# This  method is in another file
def uploadToGoogleDrive(file):
    gauth = GoogleAuth()
    gauth.LoadCredentialsFile("upload/mumopcreds.txt")
    if gauth.credentials is None:
        gauth.LocalWebserverAuth()
    elif gauth.access_token_expired:
        gauth.Refresh()
    else:
        gauth.Authorize()
    gauth.SaveCredentialsFile("upload/mumopcreds.txt")
    drive = GoogleDrive(gauth)
    file1 = drive.CreateFile()
    file1.SetContentFile(file)
    file1.Upload()

简单的方法是在
self.statusBar().showMessage(…)
之后添加。 这应该在使用google访问阻止事件队列之前处理所有UI更新

一种更复杂的方法是将google访问外包到另一个线程中(参见示例),但对于您的用例来说,这可能有点过头了。

QApplication.processEvents()非常适合。谢谢