我尝试在没有 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
最佳答案
您不能在 try/except
之上使用像 @ray.remote
这样的装饰器,这会导致 SyntaxError
。
您需要将 try/except 包装在函数周围,并装饰该函数。例如
@ray.remote
def Func2():
try:
Func1()
except:
pass
关于python - 我编写的代码在尝试 : 时抛出无效语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56319476/