Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cxfreeze executable stuck on infinite loop on Ubuntu18.04 #501

Closed
danzigjabalpur opened this issue Sep 4, 2019 · 9 comments · Fixed by #1956
Closed

cxfreeze executable stuck on infinite loop on Ubuntu18.04 #501

danzigjabalpur opened this issue Sep 4, 2019 · 9 comments · Fixed by #1956

Comments

@danzigjabalpur
Copy link

As per title, im running on ubuntu 18.04(virtualbox) and Python 3.6 and im working in a venv. When I run the executable, it goes into an infinite loop asking for my input and when i try to break the loop, it shows me the same error forever resulting in me having to force close the terminal.

danzig@ubuntu-vb:/Desktop/linreg_io/build/exe.linux-x86_64-3.6$ ./linreg_io
Input Voltage Reading: Input Voltage Reading: Input Voltage Reading: qInput Voltage Reading:
danzig@ubuntu-vb:~/Desktop/linreg_io/build/exe.linux-x86_64-3.6$ Input Voltage Reading: Traceback (most recent call last):
File "/home/danzig/Desktop/linreg_io/venv/lib/python3.6/site-packages/cx_Freeze/initscripts/startup.py", line 40, in run
module.run()
File "/home/danzig/Desktop/linreg_io/venv/lib/python3.6/site-packages/cx_Freeze/initscripts/Console.py", line 23, in run
exec(code, {'name': 'main'})
File "linreg_io.py", line 18, in
File "linreg_io.py", line 7, in main
EOFError
Input Voltage Reading: Traceback (most recent call last):
File "/home/danzig/Desktop/linreg_io/venv/lib/python3.6/site-packages/cx_Freeze/initscripts/startup.py", line 40, in run
module.run()
File "/home/danzig/Desktop/linreg_io/venv/lib/python3.6/site-packages/cx_Freeze/initscripts/Console.py", line 23, in run
exec(code, {'name': 'main'})
File "linreg_io.py", line 18, in
File "linreg_io.py", line 7, in main
EOFError
Input Voltage Reading: Traceback (most recent call last):
File "/home/danzig/Desktop/linreg_io/venv/lib/python3.6/site-packages/cx_Freeze/initscripts/startup.py", line 40, in run
module.run()
File "/home/danzig/Desktop/linreg_io/venv/lib/python3.6/site-packages/cx_Freeze/initscripts/Console.py", line 23, in run
exec(code, {'name': 'main'})
File "linreg_io.py", line 18, in
File "linreg_io.py", line 7, in main
EOFError

My code is rather simple as you can see below. I encounter the same issue while using pyinstaller but I found when using freeze_support it stops the infinite looping but it doesnt work for cx_freeze. im stumped at this point...

from multiprocessing import freeze_support
from sklearn.linear_model import LinearRegression
import pickle
import numpy as np

def main():

    while True:

    userinput = input("Input Voltage Reading: ")

    if userinput == "q":

        break

    userinput = np.array(float(userinput))

    loaded_model= pickle.load(open('finalized_model.sav','rb'))

    result = loaded_model.predict(userinput.reshape(-1,1))
  
    print(result)

if __name__ == '__main__':
   freeze_support()
    main()

and heres my setup.py if it helps.

    import sys
    from cx_Freeze import setup, Executable

    build_exe_options = ['numpy.core._methods', 'numpy.lib.format']
    includefiles = [(r'/home/danzig/Desktop/linreg_io/venv/lib/python3.6/site-packages/scipy')]

    setup(  name = "linreg_io",
            version = "0.1",
            description = "linear regression",
            options = {"build_exe": {'includes':build_exe_options,'include_files':includefiles}},
            executables = [Executable("linreg_io.py")] )

I appreciate any help I can get.

@marcelotduarte
Copy link
Owner

This program runs in python?
Please attach (not paste, attach to preserve indentation) the main and setup modules...

@marcelotduarte
Copy link
Owner

No answer. If necessary, reopen.

@Chounes
Copy link

Chounes commented Mar 16, 2022

Hello, I am currently having the same problem, if someone has found the solution in the meantime, it would help me a lot!
Thank you in advance for your answers

@zetaloop
Copy link

This is a bug of multiprocessing (see multiprocessing freeze_support needed outside win32 #76327). On systems other than Windows, multiprocessing's freeze_support function does not really work. In these frozen executables, those spawn subprocesses, forkserver processes, and resource tracker processes will judge themselves as the main process, causing an infinite loop. This problem has been postponed for many years and has not been fixed yet.

PyInstaller has made a hook for this bug (see pyi_rth_multiprocessing.py), so you can use PyInstaller to build multiprocessing programs, and run them correctly. However, cx_Freeze won't do anything about this, so you won't be able to run your multiprocessing programs correctly on linux and macos through cx_Freeze.

I planned to fix this problem for multiprocessing these days, but it may not be done so quickly.

At present, you can simply use PyInstaller to pack your multiprocessing program, it should work.

@zetaloop
Copy link

zetaloop commented May 13, 2023

Maybe cx_Freeze should add a hook for this too, as the bug will still be there for a long time...

Because cx_Freeze does not support single file mode, our hook only needs to patch multiprocessing.freeze_support and multiprocessing.spawn.freeze_support.

@marcelotduarte
Copy link
Owner

marcelotduarte commented May 15, 2023

I use multiprocessing in Linux. I doesnot use with numpy, sklearn, but with Flask.

I used:
from multiprocessing import Process, freeze_support

As cx_Freeze can generate multiple executables, I use Process to start the child process.
In this article, in the topic "Example of Adding Freeze Support for Multiprocessing" has a code similar to what I implemented. And, obviously I use cx_Freeze instead of freeze.py

For the other side, the open issue #588, using a "spawn" can be replicated, but it may be converted to use this method.

@marcelotduarte
Copy link
Owner

You can test the patch in the latest development build:
pip install --upgrade --pre --extra-index-url https://marcelotduarte.github.io/packages/ cx_Freeze

I tested the PR in Ubuntu 20.04 Python 3.10.6 but I expect that it should work from Python 3.8 to 3.12.

@marcelotduarte
Copy link
Owner

marcelotduarte commented Jul 10, 2023

@zetaloop I based myself on issue #264 to make the patch, but today I came across your patch python/cpython#104607 directly in CPython. I had thought that you would make a patch for cx_Freeze, but as you didn't, I did. Anyway, I think CPython is the correct, definitive way.
If your patch is accepted, say, for version 3.11.5 and 3.12, I put a conditional.

@marcelotduarte
Copy link
Owner

Release 6.15.4 is out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants