zoukankan      html  css  js  c++  java
  • python3下tomorow模块 @thread报语法错误def async(n, base_type, timeout=None): ^ SyntaxError: invalid syntax---解决方法

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

    这是报错信息:
    Traceback (most recent call last):
      File "C:/programmer/boyuncar900_v1/main.py", line 5, in <module>
        from tomorrow import threads
      File "C:programmerpythonlibsite-packages omorrow_init_.py", line 1, in <module>
        from .tomorrow import threads
      File "C:programmerpythonlibsite-packages omorrow omorrow.py", line 20
        def async(n, base_type, timeout=None):
                ^
    SyntaxError: invalid syntax

    解决办法:async是python关键字,源代码换个函数名,比如async_tm。

    from tomorrow import threads
    
    
    def add_case(case_path=casepath, rule="test*.py"):
    
        pass
    
    @threads(5)
    def run_case(all_case, report_path=reportpath, nth=0):
    
        '''执行所有的用例, 并把结果写入测试报告'''
    
        pass

     

    解决办法:async是python关键字,源代码换个函数名,比如async_tm。

    def async_mc(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_mc(n, ThreadPoolExecutor, timeout)
  • 相关阅读:
    eclipse中文乱码问题解决方案
    修改Tomcat的JDK目录
    Tomcat 5.5 修改服务器的侦听端口
    HTML DOM教程 27HTML DOM Button 对象
    HTML DOM教程 24HTML DOM Frameset 对象
    Navicat for MySQL v8.0.27 的注册码
    HTML DOM教程 25HTML DOM IFrame 对象
    Tomcat 5.5 的下载和安装
    android manifest相关属性
    ubuntu10.04 下 eclipse 小结
  • 原文地址:https://www.cnblogs.com/xyao1/p/10912881.html
Copyright © 2011-2022 走看看