Subprocess .wait() is not waiting
Hi, 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) 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. -- https://mail.python.org/mailman/listinfo/python-list
Re: Subprocess .wait() is not waiting
On Friday, March 24, 2017 at 12:51:02 PM UTC-7, Chris Angelico wrote: > On Sat, Mar 25, 2017 at 6:40 AM, Ian Kelly wrote: > > If that's what's happening it would be a bug. Are you sure that the > > other program isn't simply crashing or otherwise failing to complete? > > > > Or possibly is running asynchronously. Is this a GUI app? A lot of > Windows GUI programs don't wait when you invoke them. > > ChrisA Aha! Since the Excel app is a GUI app it's not waiting is that right? -- https://mail.python.org/mailman/listinfo/python-list
Re: Subprocess .wait() is not waiting
On Friday, March 24, 2017 at 12:55:30 PM UTC-7, adam.c.bernier wrote: > On Friday, March 24, 2017 at 12:51:02 PM UTC-7, Chris Angelico wrote: > > On Sat, Mar 25, 2017 at 6:40 AM, Ian Kelly wrote: > > > If that's what's happening it would be a bug. Are you sure that the > > > other program isn't simply crashing or otherwise failing to complete? > > > > > > > Or possibly is running asynchronously. Is this a GUI app? A lot of > > Windows GUI programs don't wait when you invoke them. > > > > ChrisA > > Aha! Since the Excel app is a GUI app it's not waiting is that right? If that's the case is there any workaround? -- https://mail.python.org/mailman/listinfo/python-list
Re: Subprocess .wait() is not waiting
On Friday, March 24, 2017 at 12:41:22 PM UTC-7, Ian wrote: > On Fri, Mar 24, 2017 at 12:42 PM, adam.c.bernier > wrote: > > Hi, > > > > 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) > > 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. > > If that's what's happening it would be a bug. Are you sure that the > other program isn't simply crashing or otherwise failing to complete? > > By the way, the wait in the code above is redundant because > communicate already waits. Thank you for the comment about the wait being redundant. Much appreciated. -- https://mail.python.org/mailman/listinfo/python-list
Re: Subprocess .wait() is not waiting
On Friday, March 24, 2017 at 1:09:49 PM UTC-7, Chris Angelico wrote: > On Sat, Mar 25, 2017 at 6:55 AM, adam.c.bernier wrote: > > On Friday, March 24, 2017 at 12:55:30 PM UTC-7, adam.c.bernier wrote: > >> On Friday, March 24, 2017 at 12:51:02 PM UTC-7, Chris Angelico wrote: > >> > On Sat, Mar 25, 2017 at 6:40 AM, Ian Kelly wrote: > >> > > If that's what's happening it would be a bug. Are you sure that the > >> > > other program isn't simply crashing or otherwise failing to complete? > >> > > > >> > > >> > Or possibly is running asynchronously. Is this a GUI app? A lot of > >> > Windows GUI programs don't wait when you invoke them. > >> > > >> > ChrisA > >> > >> Aha! Since the Excel app is a GUI app it's not waiting is that right? > > > > If that's the case is there any workaround? > > Errr been a while since I messed with Windows from memory, I > think you can "start /wait programname" to make it wait?? Worth a try, > at least. > > Otherwise, your best bet would be to wait in a completely different > way. Give the app a specific file name to use as a signal, and when > it's done, it should create that file. You then watch for that file, > and when it exists, you move on. > > ChrisA Thank you! I will try the first answer here http://stackoverflow.com/questions/11615455/python-start-new-command-prompt-on-windows-and-wait-for-it-finish-exit and see where that gets me. Thanks again for your thoughts. -- https://mail.python.org/mailman/listinfo/python-list
Re: Subprocess .wait() is not waiting
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 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. -- https://mail.python.org/mailman/listinfo/python-list
Re: Subprocess .wait() is not waiting
On Friday, March 24, 2017 at 2:27:09 PM UTC-7, eryk sun wrote: > On Fri, Mar 24, 2017 at 8:44 PM, adam.c.bernier wrote: > > On Friday, March 24, 2017 at 1:37:49 PM UTC-7, eryk sun wrote: > > > >> 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. > > openpyxl should do all of the work in the process that Popen is > waiting on. Is the command-line in `args` something like > "C:\Python27\python.exe path\to\script.py"? That's exactly right. -- https://mail.python.org/mailman/listinfo/python-list