相关疑难解决方法(0)

替代 asyncio.wait?

我收到此错误:

D:\pythonstuff\demo.py:28: DeprecationWarning: 自 Python 3.8 起不推荐将协程对象显式传递给 asyncio.wait(),并计划在 Python 3.11 中删除。等待 asyncio.wait([

等了1秒!
等了5秒!
经过的时间:0小时:0分:5秒

进程以退出代码 0 结束

当我运行代码时

import asyncio
import time

class class1():
    async def function_inside_class(self):
        await asyncio.sleep(1)
        print("Waited 1 second!")

    async def function_inside_class2(self):
        await asyncio.sleep(5)
        print("Waited 5 second!")

def tic():
    global _start_time
    _start_time = time.time()

def tac():
    t_sec = round(time.time() - _start_time)
    (t_min, t_sec) = divmod(t_sec,60)
    (t_hour,t_min) = divmod(t_min,60)
    print('Time passed: {}hour:{}min:{}sec'.format(t_hour,t_min,t_sec))

object = class1()


async def main():
    tic()
    await asyncio.wait([
        object.function_inside_class(),
        object.function_inside_class2()
        ])
    tac() …
Run Code Online (Sandbox Code Playgroud)

python asynchronous python-3.x python-asyncio python-3.8

2
推荐指数
1
解决办法
1759
查看次数

抑制 python 中的弃用

所以 - 我正在使用库 pyminizip - 这是我发现创建受密码保护的 zip 文件的唯一方法。当我使用它时,我收到一条弃用警告:“#”格式将需要 PY_SSIZE_T_CLEAN。

现在,我无法控制该库,无法修复它 - 我似乎也没有一个简单的替代方案来使用它 - 而且它工作得很好。因此,弃用警告给我带来了零价值 - 但它干扰了我的工具的 UI - 正如它出现在标准输出上一样。有什么办法可以抑制它/让它消失吗?

我称呼它的方式是:

   import pyminizip
   pyminizip.compress_multiple( [ prod_report ], [], f"C:/temp/report{name}.zip", "Password", 9 )
Run Code Online (Sandbox Code Playgroud)

python deprecated

2
推荐指数
1
解决办法
6331
查看次数

在 GCP 脚本中使用最终用户凭据时禁用警告

我正在使用Python 客户端库运行一些脚本来在 GCP 中执行一些临时作业。
这些是临时的,因此我相信它们应该在我的最终用户凭据而不是服务帐户上运行。

我不断看到此警告,这使得调试我的脚本标准输出变得困难:

UserWarning: Your application has authenticated using end user credentials from Google Cloud SDK without a quota project. You might receive a "quota exceeded" or "API not enabled" error. We recommend you rerun `gcloud auth application-default login` and make sure a quota project is added. Or you can use service accounts instead. For more information about service accounts, see https://cloud.google.com/docs/authentication/
Run Code Online (Sandbox Code Playgroud)

我执行了建议的操作gcloud auth application-default login,但仍然重复出现相同的警告消息。

如何禁用此警告?

google-cloud-platform

1
推荐指数
1
解决办法
5476
查看次数

无法抑制 fasttext 警告:'load_model' 不返回 [...]

我正在努力抑制与fasttext.

警告是 Warning : 'load_model' does not return WordVectorModel or SupervisedModel any more, but a 'FastText' object which is very similar.

这是有问题的代码块:

with warnings.catch_warnings():
    warnings.filterwarnings('ignore')
    return fasttext.load_model(str(model_path))  # this line
Run Code Online (Sandbox Code Playgroud)

我尝试了几种方法来抑制警告,主要是从这个线程没有成功。

我正在使用Python 3.8fasttext v0.9.2

python warnings fasttext

1
推荐指数
1
解决办法
758
查看次数