Python:在多处理中不优先输出函数

Python:在多处理中不优先输出函数,python,multiprocessing,Python,Multiprocessing,我想对我的代码使用多处理,我在这里尝试了这个示例: 但是,当我运行代码时,它不会打印任何内容。如果你能帮我找出原因,我将不胜感激?如何修复它 我正在使用Python 3和Spider 编辑1: 使用sys.stdout.flush()没有帮助。我试图将其添加到worker函数中 def worker(num): """thread worker function""" print('Worker:', num) sys.stdout.flush() return

我想对我的代码使用多处理,我在这里尝试了这个示例:

但是,当我运行代码时,它不会打印任何内容。如果你能帮我找出原因,我将不胜感激?如何修复它

我正在使用Python 3和Spider

编辑1: 使用sys.stdout.flush()没有帮助。我试图将其添加到worker函数中

def worker(num):
    """thread worker function"""
    print('Worker:', num)
    sys.stdout.flush()
    return
编辑2 类似于这个问题。。。但即使我尝试了建议的解决方案,它也不起作用

编辑3

事实上,不使用spyder,它就起作用了:


如果刷新缓冲区怎么办?@LukaszTracewski感谢您的评论。我试过了。它没有改变输出。这可能与此问题有关吗@po.pe我尝试了建议的答案,但没有改变:/Good thinking@po.pe我会在Spyder之外运行脚本。我也有Spyder引起的问题。
def worker(num):
    """thread worker function"""
    print('Worker:', num)
    sys.stdout.flush()
    return