Python Gio 等待异步操作完成

0 投票
1 回答
564 浏览
提问于 2025-04-15 21:50

我需要挂载一个WebDav的位置,并且在这个操作完成之前不进行其他操作(这是一个脚本)。

所以我这样使用这个库:

location = gio.File("dav://server.bb")
location.mount_enclosing_volume(*args,**kw) # The setup is not much relevant
location.get_path() # Returns None because it's not yet mounted since the call is async

我该如何等待设备挂载完成呢?

1 个回答

1

要等待操作完成,你需要使用 mount_enclosing_volume_finished 这个方法,并把之前通过 mount_enclosing_volume 得到的异步结果对象传进去(另外,如果你想要异步操作的话,也可以给 mount_enclosing_volume 传一个回调函数,但看起来你这里想要的是同步的操作)。

撰写回答