1

我试图在没有 def 的情况下做到这一点,这是我真的不知道该怎么做的代码我也试图正确地给出缩进

但是当我运行它时,它会抛出错误无效语法

import ray

ray.init()

@ray.remote
try:
    Func1()
except:
    pass



ray.get([func1.remote()])



def func1():
    for i in range (99999):
        print("h")```

The error is invalid syntax at try:




This is the code that worked for me 


try:
    do_something()
except:
    pass



4

1 回答 1

1

您不能@ray.remote在 . 顶部有一个装饰器try/except,这会导致SyntaxError.

您需要将 try/except 包装在一个函数周围,并装饰该函数。例如

@ray.remote
def Func2():
    try:
        Func1()
    except:
        pass
于 2019-05-27T03:54:56.017 回答