Toa*_*ast 3 python multithreading
我想将此方法作为线程启动:
server.run('0.0.0.0', threaded=True)
Run Code Online (Sandbox Code Playgroud)
这是不使用关键字参数的情况下的方法:
start_new_thread(server.run, ('0.0.0.0', None, False))
Run Code Online (Sandbox Code Playgroud)
这是我的丑陋解决方案:
def startServer():
server.run('0.0.0.0', threaded=True)
start_new_thread(startServer, ())
Run Code Online (Sandbox Code Playgroud)
可以一行完成吗?
如果start_new_thread没有**kwargs参数,则可以使用:
from functools import partial
start_new_thread(partial(server.run, "0.0.0.0", threaded=True))
Run Code Online (Sandbox Code Playgroud)
或者简单地:
start_new_thread(server.run, ("0.0.0.0",), {"threaded": True})
Run Code Online (Sandbox Code Playgroud)
希望能帮助到你!