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
Related
I'm a student and got the opportunity to write a python program set for a friend's company's production area. It is basically several math functions with error checking and a menu. Finished the program and it works well, but I have one concern.
The program needs to be scalable, which I have built in templates to do so.
The problem I have right now is its only launchable via an IDE.
I don't want the workers to see the code, and accidently break the code when launching.
But I also don't want to compile the code into an apk, as it needs to be easily changeable.
So my question is thus: is there any way to make an apk that just launches the core script, brings up a python console and loads it's dependencies from a file structure that can easily be accessed by something like qPython without first showing the code to the user?
The reason this is necessary, is the people in charge who will write new programs only know qPython and program stuff as if it were fortran, adding a layer of something like Android Studio might make it where they never remember how to update their program, thus never do so.
Everywhere I look there is only options pull the whole script into an apk.
Thanks in advance for the input.
So tl:dr looking for a method to have push button run python console script on a android, if it exists.
I am learning Python (v 3.7) on a Mac using PyCharm. As I practice using the turtle library, the program runs without error, outputs the correct graphics, but then the graphics screen disappears immediately after the code completes runnning. Adding time.sleep(5) at the end of my program persists it and also shows that the focus changed from PyCharm to a Python program menu (which I can't find or turn on in the hope of keeping running).
When I use Thonny, the output persists, so I can check my work. How can I make it persist in PyCharm?
A well-structured Python turtle program will end with a call to mainloop() or one of its variants (exitonclick(), done()) This turns control over to the underlying tkinter event handler which will keep your window open, awaiting user events. Without this, the program simply ends and the window closes.
You don't need time.sleep() nor input("Press Enter to continue..."). Some Python programming environments clash with mainloop() but even those tend to disable it behind the scenes so the same code works everywhere.
First, do not use PyCharm to test. If you like it, more power to you, but personally, I have had many issues with output and PyCharm. Learn the command line, since you are using Mac. CodeAcacdemy and LinuxJournery have really good resources on that subject. Second, if you are still having issues, please reinstall trutle, Python 3.7 (there were some issues wiht it displaying on Mac), and macOS itself. Have a great day!
https://linuxjourney.com/
https://www.codecademy.com/learn/learn-the-command-line
Problems getting pygame to show anything but a blank screen on Macos Mojave
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)
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.
Beginner here. I am trying to figure out how to modify a running process on a linux system using Python.
Example: I have a python program that takes in as an argument a PID. My goal is to use this PID and get info about the running process with that PID.
(1) Find where it is located in memory
(2) Where is the instruction pointer
(3) Modify the program such that the next executed instruction is something else
(4) Return the pointer back to the next legitimate instruction
(5) Let the original process execute as it should have
I am trying to develop a POC to show how a small piece of code can be injected into a running process to just print 'hello' to stdout and not disturb the rest of the process.
I looked up trace and some other modules but they all seem to do with following the currently executing python process. Also looked at pyhook, but its mainly to trap signals from keyboards etc.. additionally, I looked up pygdb a bit.
Can anyone please point me to some modules that might be useful, or some code samples. I tried googling for "python inspect process PID" etc.. did not get anything very useful.
Any help is very appreciated.
Thanks!
Also a newer python user. Can you do all these things with just the command line? If so then you could use os.system('[command]') or the subprocess module. For example you could use the pmap command to get the memory mappings. As for 2-5 I have no experience there. Good Luck.