multiprocessing.Process()刚刚停止工作

时间:2019-11-24 02:21:53

标签: python python-3.x multithreading python-multiprocessing

我在Spyder上自学使用Python进行多处理,并在突然停止工作时通过一些相对简单的示例进行研究。回到以前曾经工作过的一些简单示例,现在看来它们似乎也不起作用。我想不出我该怎么做才能让他们停止工作。下面是我的代码:

import time
import multiprocessing

start = time.perf_counter()

def do_something():
    print('Sleeping 1 second...')
    time.sleep(1)
    print('Done Sleeping...')


p1 = multiprocessing.Process(target = do_something)
p2 = multiprocessing.Process(target = do_something)

p1.start()
p2.start()

p1.join()
p2.join()


finish = time.perf_counter()


print(f'Finished in {round(finish - start, 2)} second(s)')

它似乎好像在中间部分一样运行:

p1 = multiprocessing.Process(target = do_something)
p2 = multiprocessing.Process(target = do_something)

p1.start()
p2.start()

p1.join()
p2.join()

不在吗?

编辑

唯一的输出是

Finished in 0.64 second(s)

没有错误消息。

1 个答案:

答案 0 :(得分:2)

您需要阅读function calcSin(){ try{ //Checks for syntax errors if(calcString[calcString.length-1] == "+" || calcString[calcString.length-1] == "-" || calcString[calcString.length-1] == "*" || calcString[calcString.length-1] == "/"){ throw "Syntax Error" } } catch(err){ document.getElementById("screenPar").innerHTML = err; return 1; } if(calcString[calcString.length-1] == "$"){ //If last character in string is '$', clears screen clearScreen(); document.getElementById("screenPar").style.color = "black"; } else{ var evalRes = eval(calcString); console.log(evalRes + typeof evalRes); var result = Math.round(Math.sin(evalRes)); console.log(result + typeof result); clearScreen(); console.log(result); document.getElementById("screenPar").innerHTML = result; } } 并按照说明进行操作!

error

请运行以下代码:

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()
                ...

        The "freeze_support()" line can be omitted if the program
        is not going to be frozen to produce an executable.