为什么 huggingface 挂在管道情感分析的列表输入上?

Why does huggingface hang on list input for pipeline sentiment-analysis?

使用 python 3.10 和最新版本的 huggingface。

像这样的简单代码

from transformers import pipeline

input_list = ['How do I test my connection? (Windows)', 'how do I change my payment method?', 'How do I contact customer support?']

classifier = pipeline('sentiment-analysis')
results = classifier(input_list)

程序挂起并且 returns 错误消息:

File ".......env/lib/python3.10/multiprocessing/spawn.py", line 134, in _check_not_importing_main
    raise RuntimeError('''
RuntimeError: 
        An attempt has been made to start a new process before the
        current process has finished its bootstrapping phase.

        This probably means that you are not using fork to start your
        child processes and you have forgotten to use the proper idiom
        in the main module:

            if __name__ == '__main__':
                freeze_support()
                ...

但是用字符串替换列表输入,它有效

from transformers import pipeline
classifier = pipeline('sentiment-analysis')
result = classifier('How do I test my connection? (Windows)')

列表输入依赖的运行多任务需要定义一个main函数。以下更新有效

from transformers import pipeline

def main():
    input_list = ['How do I test my connection? (Windows)', 
    'how do I change my payment method?',
    'How do I contact customer support?']

    classifier = pipeline('sentiment-analysis')
    results = classifier(input_list)

if __name__ == '__main__':
    main()

问题缩减为where to put freeze_support() in a Python script?