我注意到我可以访问子进程函数/目标之外的子进程中的函数和模块。所以我想知道当我在 python 中创建一个子进程时,它是否从当前进程中复制了所有内容?为什么我可以访问子目标之外的函数和导入的模块?
from multiprocessing import Process, Pipe
def test1():
return "hello"
def simpleChildProcess( childPipe ):
# simpleChildProcess can access test1 function
foo = test1()
childPipe.send( foo )
parentPipe, childPipe = Pipe()
childProcess = Process( target=simpleChildProcess, args=(childPipe,) )
childProcess.start()
print "Pipe Contains: %s" % parentPipe.recv()
Run Code Online (Sandbox Code Playgroud) 通常的参数是(String [] arg).这个我接受一个带字符串数组的参数.当我将其更改为(Int arg)时,我得到一个运行时错误"没有这样的方法错误".我知道错误是由更改参数引起的.我的问题是我可以将参数从String数组更改为其他内容,还是只能使用预设参数?