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)
  • 相关阅读:
    查看unity打来的包在手机上面查看日志
    Unity 打包出来动态加载图片丢失问题
    嵌套列表拖拽事件冲突问题
    游戏中实现鼠标拖尾效果
    2048
    面试知识点积累
    ARM处理器架构理论知识
    計算機網絡知識點總結:
    collection
    demo002.链表操作
  • 原文地址:https://www.cnblogs.com/xyao1/p/10912881.html
Copyright © 2011-2022 走看看