Im trying to start a wxPython app that (I have converted to an exe with py2exe) from a process that is running in the background.
The problem is that when the gui app opens, so does a console window (c:\windows\system\cmd.exe)
I had a look at this question where Alex Martelli suggests setting the creationflags
paramater of Popen
to 0x08000000
but this hasn't solved my problem.
Also I wonder if there is a better way of running a process in the background, at the moment I just changed the extension of the script to pyw
and since it doesn't have a GUI then it isn't visible...
This is line that calls the subprocess
subprocess.Popen(args="%s"%comPort,bufsize=0,
executable="myFrozen_WxpythonApp.exe",
creationflags=0x08000000, shell=False)
py2exe script
...
options = {'py2exe': {'compressed': 3,
'optimize': 2,
'excludes': excludes,
'packages': packages,
'dll_excludes': dll_excludes,
'bundle_files': 1,
'dist_dir': 'dist',
'xref': False,
'skip_archive': False,
'ascii': False,
#'packages': packages,
'custom_boot_script': '',
}
}
setup(options=options, windows=["app.pyw"], zipfile=None, data_files=data_files)
Update:
As I explained in my answer to this question the problem was in the subprocess.Popen
call.
The first string in the args parameter should be the name of the executable, the executable name can then be followed by any commands or data that needs to be passed to the subprocess.
Popen do we need to close the connection or subprocess automatically closes the connection? Usually, the examples in the official documentation are complete. There the connection is not closed. So you do not need to close most probably.
Popen is more general than subprocess. call . Popen doesn't block, allowing you to interact with the process while it's running, or continue with other things in your Python program. The call to Popen returns a Popen object.
Popen is nonblocking. call and check_call are blocking. You can make the Popen instance block by calling its wait or communicate method.
The subprocess module provides a function named call. This function allows you to call another program, wait for the command to complete and then return the return code.
I figured out what I was doing wrong after reading the documentation for subprocess.Popen
The first string in the args
parameter should be the name of the executable. I didn't include the name of the executable as I thought that was taken care of with the executable
paramater.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With