Basically it's all in the title, when I run the code from a console (on Windows) the child process runs without opening another console, but when I run the code from the cx_freeze'd app another console opens.
I found this old thread where was suggested to use FreeConsole(), it will flash the console on screen for a blink but I can eventually live with it, unfortunately if i understood correctly it should be called from the child process.
http://twistedmatrix.com/pipermail/twisted-python/2007-February/014738.html
I also found this ticket (7yo) on a re-factoring of the whole spawnProcess on windows but apparently it never happened:
http://twistedmatrix.com/trac/ticket/2415
I have no control over the code of the child process, so doing something there is unfortunately not an option, but even if I did the process I'm spawning it's a console app and I believe FreeConsole() could not be called there or the process will terminate.
This is possibly a bug in Twisted, but possibly a bug in cx_Freeze.
What happens when you run the code from the GUI with Python, but without cx_Freeze involved? You should be able to test this if you have Python installed by simply putting your code into a .pyw file and double-clicking on it in Explorer.
If this still pops up a console window when you run your subprocess, then this is totally a bug in Twisted and you should file it as such. Eric's answer in that mailing list message is wrong; if you want to spawn processes with spawnProcess they definitely shouldn't be popping up random console windows.
If the click-on-a-.pyw launching method doesn't cause a console window to pop up, then it's probably something about the way cx_Freeze has constructed your executable and you might want to look at it.
On UNIX, we have a platform-specific usePTY, so it makes sense that we could expand spawnProcess with a platform-specific useConsole that would do something analogous for Windows. This later message in the thread suggests an implementation strategy, so please file a ticket. The let's-redo-everything ticket is too ambitious to fix this one issue.
Related
Good Day All,
I finished writing the site blocker process and then i renamed the "py" file by appending "w", double clicked to run it yet the process did not show up in the task manager. I tried it a few times and yet nothing showed up. Mind you I am on Win 10 OS.
You have any suggestions to help fix this such that is shows up in the task manager as pythonw.exe process ?
If the process isn't showing up in the Task Manager, it's very likely that it's immediately quitting with an error. Even trivial changes to the code cause this to occur. Without the console showing output it's hard to tell what that error is. Try renaming the file back to filename.py and running it to see if an error is occurring.
Another possibility is that the script is completing so fast you don't have time to see it. Did it run instantaneously when it was named filename.py?
I have made a GUI for my application. All scripts are in Python (2.7) and the GUI is created with Tkinter. I work on Linux, but I needed this app to be executable on Windows. So I've used py2exe, to create an executable. After a while it is working almost perfectly, but I have the following problem:
Somewhere in the application, I need to call external programs, namely ImageMagick and LaTeX. I use the commands convert, pdflatex, simply by importing os module and running os.system(build), where build = 'convert page.pdf page.gif'etc. When those commands are called from the *.exe application the console pops up (meaning a console window opens up for a split of a second and closes again). Is there a way, to prevent this behaviour?
It does not interrupt the application, but it is ugly and not a desired behaviour.
[Note] I chose not to add any samples, since there are lots of files and other content, which, I think, is not related to the problem. I could however try to post minimal (not)working example. But maybe it is not needed.
Thanks!
import subprocess
subprocess.Popen("application.exe", shell = True)
I am currently working on a program that will back up my Skype and iTunes data. It works fine with my iTunes data, however, when I try to backup files from Skype I get loads of errors. These are caused from the program still being open.
I thought it would be a fun little project to try and find out how to force quit a program (and then re-open).
I have successfully learned how to OPEN Skype (with a simple statement,
import os
os.startfile(path) #this opens programs. I need to close.
So I think to get my program to work, all I would need to do is close skype, run the backup process, then re-open it.
When I tried searching my question, I was only finding answers to close PYTHON scripts. I need to close something that is running in Windows.
I have found the answer.
import os
os.system("taskkill /im skype.exe") #/im means "ImageName"
taskkill is a command-line reference.
"Ends one or more tasks or processes. Processes can be killed by process ID or image name"
http://technet.microsoft.com/en-us/library/bb491009.aspx
Thank you #furas for leading me to the page with the answer. I'm surprised I missed it, I tried searching for a while.
I wrote a small multiprocessing application and then wrote a PyQt front end for it. When I run the script by calling it from the command line with Python (or by calling run from the Spyder IDE), it runs exactly as I would expect and works nicely.
But if I try to use Py2Exe to make an executable to give it to a friend, it starts behaving oddly. When the users hits the botton that really starts the process and invokes the multithreading portion, it spawns multiple Qt windows that look like the original. It then essentially locks up. Closing one of the new windows that it spawns causes it to reopen that window. Attempting to close the original generates a message that it is not responding.
I would appreciate any help or suggestions about where to look.
I'm not positive about this without looking at your code, but there are some extra considerations when using Py2Exe with multithreading.
Take a look at this link and maybe it has something to do with your problem.
Someone has a similar sounding issue here
I can't seem to find the right google search to figure out something that should be easy.
I am using wxPython to create a GUI, and saving the Python files as .pyw so I don't have a console. Then I am importing another .py file into the main window when a user does an action. Doing so created the pythonw.exe instance that won't close. To be clear, the .pyw that opens if I only open the main console will clear from my processes if I don't open/insert the other .py file from the first file while running.
When I use the program everything is perfectly fine, but when I use the Windows "X" button to close I still get pythonw.exe in my processes, and the file I am printing errors to is locked due to something else using it(the pythonw.exe). What code do I need to use to make sure that python is exiting completely? It also seems to stay whenever I build in a file - exit as well, and it is only staying on the processes if I insert the other module(only done with user input)
Also this may be obvious but if I open the imported file manually it has the same behavior, as in the python.exe closes when I close out of the file.
If you want to exit the application you can do this like this:
import os
os._exit(0)
This works when the normal exit() or reaching the end of the main file does not work becaus of background threads running.
But so you are ending killing all running threads. You should look into the code of the imported file which causes the problem to see if it has threads.