YJ993 large avatar
测试学习小组  ›  python selenium

python使用tomorrow实现多线程,tomorrow模块的源代码报语法错误?

By YJ993 at 20 天前 , 71 次浏览

这是报错信息:
Traceback (most recent call last):
File "C:/programmer/boyuncar900_v1/main.py", line 5, in <module>
from tomorrow import threads
File "C:\programmer\python\lib\site-packages\tomorrow_init_.py", line 1, in <module>
from .tomorrow import threads
File "C:\programmer\python\lib\site-packages\tomorrow\tomorrow.py", line 20
def async(n, base_type, timeout=None):
^
SyntaxError: invalid syntax
源代码信息:
from functools import wraps

from concurrent.futures import ThreadPoolExecutor

class Tomorrow():

def __init__(self, future, timeout):
self._future = future
self._timeout = timeout

def __getattr__(self, name):
result = self._wait()
return result.__getattribute__(name)

def _wait(self):
return self._future.result(self._timeout)

def async(n, base_type, timeout=None):
def decorator(f):
if isinstance(n, int):
pool = base_type(n)
elif isinstance(n, base_type):
pool = n
else:
raise TypeError(
"Invalid type: %s"
% type(base_type)
)

    @wraps(f)
def wrapped(*args, **kwargs):
return Tomorrow(
pool.submit(f, *args, **kwargs),
timeout=timeout
)
return wrapped
return decorator

def threads(n, timeout=None):
return async(n, ThreadPoolExecutor, timeout)

1 回复
乙醇 medium avatar
#1 - 7 天前
乙醇

报错信息没有格式化,看不太清,但postman的node内核可能比较旧,不支持新的语法特性吧。

测试学习小组 — 软件测试学习讨论区
现在注册
已注册用户请 登入
内容分享

欢迎关注我们的公众号: 测试圈TC


小贴士

你的问题在测试教程网中能找到答案