How can I use threading in Python?

前端 未结 19 2727
迷失自我
迷失自我 2020-11-21 04:54

I am trying to understand threading in Python. I\'ve looked at the documentation and examples, but quite frankly, many examples are overly sophisticated and I\'m having trou

19条回答
  •  被撕碎了的回忆
    2020-11-21 05:10

    None of the previous solutions actually used multiple cores on my GNU/Linux server (where I don't have administrator rights). They just ran on a single core.

    I used the lower level os.fork interface to spawn multiple processes. This is the code that worked for me:

    from os import fork
    
    values = ['different', 'values', 'for', 'threads']
    
    for i in range(len(values)):
        p = fork()
        if p == 0:
            my_function(values[i])
            break
    

提交回复
热议问题