Subprocess .wait() is not waiting

adam.c.bernier adam.c.bernier at kp.org
Fri Mar 24 16:44:28 EDT 2017


On Friday, March 24, 2017 at 1:37:49 PM UTC-7, eryk sun wrote:
> On Fri, Mar 24, 2017 at 6:42 PM, adam.c.bernier <adam.c.bernier at kp.org> wrote:
> >
> > I am on Windows 7. Python 2.7
> >
> > I'm trying to have a program run another program using `subprocess.Popen`
> >
> >     import subprocess as sp
> >
> >     args = shlex.split(args)
> 
> Is this command supposed to run cross-platform? If not, then splitting
> it into a list is pointless. Windows uses a comand-line string, and
> Popen will just have to rebuild the command line from the list.
> 
> >     proc = sp.Popen(args,stdout=sp.PIPE,stderr=sp.PIPE)
> >     out, err = proc.communicate()
> >     proc.wait()
> >
> > But it *sometimes* doesn't wait and the other program -- which generates a set of
> > 14 Excel files -- does not complete before control is returned to the calling program.
> >
> > Any ideas on what I can do to make `subprocess.wait()` actually wait?
> >
> > Thanks in advance for any assistance you might be able to provide.
> 
> Without knowing the command you're running, all we can do is
> speculate. It could be that it's an application that uses a single
> instance, in which case running another instance simply messages the
> main process and then exits.

Thank you, eryk sun. The command is calling a Python script which makes calls to openpyxl to generate 14 Excel files.


More information about the Python-list mailing list