多进程Python模块的奇怪TypeError

时间:2011-08-02 04:35:36

标签: python web.py multiprocess

我正在尝试使用以下代码启动web.py服务器:

if __name__ == "__main__":
    p = Process(target=app.run) #starts the web.py server
    p.start()
    main() #starts a main listening loop for errors, testing and logging
    p.join()

,其中

app = web.application(urls, globals()) #part of the web.py framework... starts the REST server

但我得到了这个例外:

Traceback (most recent call last):
File "apitest.py", line 90, in <module>
p = Process(target=app.run)
TypeError: this constructor takes no arguments

我已经google了一下,但我找不到发生了什么......有人可以帮忙吗?

谢谢!

1 个答案:

答案 0 :(得分:1)

正如agf在评论中所建议的,您的命名空间可能相互踩踏,因此名称Process不是您认为的Process。要解决此问题,请将您导入Process的方式更改为更明确:

import multiprocessing

# ...all your other code...

p = multiprocessing.Process(target=app.run) # starts the web.py server