语法错误烧瓶应用程序

时间:2018-04-11 21:50:59

标签: python multithreading

我有以下代码:

t1 = threading.Thread(target = app.run, args = (host='0.0.0.0', port = 443))

它给了我一个错误:

File "/home/deploy/tgbot/tgbot.py", line 1170
t1 = threading.Thread(target = app.run, args = (host='0.0.0.0', port = 443))
                                                    ^

有什么问题?

1 个答案:

答案 0 :(得分:1)

app.run的顺序参数可以在元组中传递(用括号构造,但没有名称)。必须在字典中传递命名参数。字典由dict()或花括号构成,而不是括号。

由于hostportapp.run的前两个参数,因此以下任何一个都应该有效:

# positional args, passed as a tuple
t1 = threading.Thread(target=app.run, args=('0.0.0.0', 443))

# named args, passed in a dictionary created via dict()
t1 = threading.Thread(target=app.run, kwargs=dict(host='0.0.0.0', port=443))

# named args, passed in a dictionary created via {}
t1 = threading.Thread(target=app.run, kwargs={'host': '0.0.0.0', 'port': 443}))