如何在Python中使用子进程时防止应用程序崩溃

2024-04-26 13:04:39 发布

您现在位置:Python中文网/ 问答频道 /正文

向stackoverflow社区致意。我需要一些指导,如何防止我的Python cmd line应用程序在我克隆存储库的网络(GitHub)由于许多克隆请求而断开连接时崩溃。下面是我用来克隆repo的代码。目前运行良好。但是,我想,当有多人下载回购协议或者网络速度慢的时候,我会被踢出去,我的应用程序就会崩溃。我以为try/except语句可以防止崩溃,但没有用:

 ...
 command = r'git clone git@github.com:somerepo.git'
  try:
      subprocess.call(command, shell=False)
  except subprocess.CalledProcessError as cpe:
      click.echo(cpe.output)
 ...

错误:

   Git Clone Fails - error: RPC failed; result=56, HTTP code = 200

   git clone http://somerepo/repo.git
   fatal: early EOF
   fatal: The remote end hung up unexpectedly
   fatal: index-pack failed
   error: RPC failed; result=56, HTTP code = 200

Tags: git网络应用程序clonerepoerrorrpccommand