Python Pool 用进程池多进程下载git 代码时hang 在read系统调用上。
我用Python多进程来clone git 代码,其中多进程的实现使用了Python Pool
,一般情况下可以顺利的下载所有的代码,但是当存在其中某一个代码仓库的代码量远远大于其他代码仓库时,clone最大代码仓库的子进程会hang在git-lfs
上,使用strace
命令来追踪该git
进程,可以看到它卡在read
系统调用上。
Process 27649 attachedread(6, 0x7ffc36dae050, 4) = ? ERESTARTSYS (To be restarted if SA\_RESTART is set)
--- SIGALRM {si\_signo=SIGALRM, si\_code=SI\_KERNEL, si\_value={int=2895997, ptr=0x2c307d}} ---
rt\_sigreturn() = 0
read(6, 0x7ffc36dae050, 4) = ? ERESTARTSYS (To be restarted if SA\_RESTART is set)
--- SIGALRM {si\_signo=SIGALRM, si\_code=SI\_KERNEL, si\_value={int=2895997, ptr=0x2c307d}} ---
rt\_sigreturn() = 0
read(6, 0x7ffc36dae050, 4) = ? ERESTARTSYS (To be restarted if SA\_RESTART is set)
--- SIGALRM {si\_signo=SIGALRM, si\_code=SI\_KERNEL, si\_value={int=2895997, ptr=0x2c307d}} ---
rt\_sigreturn() = 0
read(6, 0x7ffc36dae050, 4) = ? ERESTARTSYS (To be restarted if SA\_RESTART is set)
--- SIGALRM {si\_signo=SIGALRM, si\_code=SI\_KERNEL, si\_value={int=2895997, ptr=0x2c307d}} ---
rt\_sigreturn()
我的多进程实现代码如下。
p = Pool(processNum) LogInfo('Parent process %s.' % os.getpid())
multi_res = [p.apply_async(runfunc, args=(
incl_info, project_root, skip_dirs,)) for incl_info in incl_infos]
LogInfo('Waiting for all subprocesses done...')
p.close()
p.join()
# 处理返回信息
resMesList = []
for res in multi_res:
resMes = str(res.get())
if (resMes.find("Failed") != -1):
#LogErr("Please check the password.")
resMesList.append(resMes)
处理函数子进程只是新启动一个shell中git clone
的subprocess.
def runfunc(incl_info,project_root,skip_dirs): if incl_info == 0:
git_url = project_root["git_url"]
dir_path = project_root["dir_path"]
GitCloneInShell(git_url,dir_path)
def GitCloneInShell(git_url,dir_path):
cmd = ("git clone %s %s " % (git_url, dir_path))
LogInfo("git clone cmd : %s" % cmd)
status = subprocess.call(cmd, shell=True)
return status
猜想是否是因为子进程的输出缓冲区被沾满了,状态转换为wait
?但是不太清楚该如何去修改。请问有遇到类似情况的朋友吗,求助。谢谢啦!
以上是 Python Pool 用进程池多进程下载git 代码时hang 在read系统调用上。 的全部内容, 来源链接: utcz.com/p/937738.html