为什么python在子进程退出时停止?

2024-06-24 13:52:08 发布

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

我使用Python的subprocess.call()运行一系列Python脚本,每个脚本都运行Matlab脚本。问题是,一旦第一个Matlab脚本结束。

外部Python脚本解析csv文件的目录,以便根据csv文件的每一行运行实验。对于每个实验,它调用一个python程序来运行解析数据并将其输入Matlab。然后运行每个实验。除了第一次运行matlab之后,整个过程都会退出。Matlab退出它的子进程会把整个事情搞垮吗?

 for line in csvfile:
      if debug:
          print 'Experiment %d' % count

      ts = line.split(',')
      startStamp=ts[0]
      cmdargs = ['python prep_lssvm.py']
      cmdargs.append(str(site))
      cmdargs.append(str(startStamp))
      cmdargs.append(str(daysTraining))

      if debug:
          print cmdargs

      for i in range(len(argv)-2):
          cmdargs.append(str(argv[i+2]))

      command = ' '.join(cmdargs)

      if debug:
          print command

      call(command,shell=True)
      #Never goes past here<<<<<<=======================
      dirname = ''.join([site,'_',str(count)])
      mkdir(dirname)
      call(''.join(['mv ',site,'/*.txt ',dirname]),shell=True,stdout=outfile)

Tags: 文件csvdebug脚本ifsitecallcommand
1条回答
网友
1楼 · 发布于 2024-06-24 13:52:08

看来我已经通过橡胶鸭调试解决了这个问题。在

我是通过Popen()调用MATLAB脚本的,它是异步执行的,而不是call(),它是同步执行的。将Popen的所有实例改为call似乎解决了这个问题。在

相关问题 更多 >