记一个很简单但很纠结的坑

python依赖包中使用了time模块,但time.clock() 函数在 Python 3.3 中被废弃,并且在 Python 3.8 中被彻底删除。

现在可以使用 time.perf_counter() 或 time.process_time() 来替换原先的 time.clock() 函数。time.perf_counter() 函数返回一个精度更高的计时器,而 time.process_time() 函数返回当前进程使用的 CPU 时间

公司平台使用的是time.clock(),安装的python版本恰好是3.8,改成time.perf_counter() 之后启动项目会报:TypeError: 'float' object is not callable

报这个错大部分原因是由于代码被判定为乘法计算,但是缺少了运算符*

这个地方之所以报错是因为源码中改动后是:

_timer = time.perf_counter()

在后面被调用时是:

if current_app:

  context._query_start_time = _timer()

_time被以为是= time.perf_counter()(),所以被认成乘法,去掉两处中任意一个()就好了...

 

(不得不感叹一声。。。好奇特的语法)

 

posted @ 2023-07-19 12:26  F_Ichigo  阅读(56)  评论(0编辑  收藏  举报