Skip to content

Conversation

@EurynomeKeros
Copy link
Contributor

Issue

  • The packaging method defines the startup logic of the application as running the "pyxapp" file
  • The execution logic of the "pyxapp" file is to extract it to the system's temporary directory and run the entry file
  • Run the packaged executable file, when multiple processes are run in a project or the program itself is executed through "subprocesses", it will cause the startup logic to be repeatedly executed, resulting in "pyxapp" file repeatedly decompressing

Reproduction

  • Use multiple processes
from multiprocessing import freeze_support,Process

def test():
    print("hello world")

if __name__=="__main__":
    freeze_support()
    process=Process(target=test)
    process.start()
    process.join()

Use the app2exe command to package it as an application and execute it. The "pyxapp" file will be decompressed twice in the temporary directory of the system
1759218213278

  • Run the program itself using "subprocess", such as the pyxel.reset() method
import pyxel

class App:
    def __init__(self):
        pyxel.init(160, 120)
        self.x = 0
        pyxel.run(self.update, self.draw)

    def update(self):
        if pyxel.btnp(pyxel.MOUSE_BUTTON_LEFT):
            pyxel.reset()
        self.x = (self.x + 1) % pyxel.width

    def draw(self):
        pyxel.cls(0)
        pyxel.rect(self.x, 0, 8, 8, 9)

App()

Use the app2exe command to package it as an application and execute it. Whenever the pyxel.reset() method is triggered, the "pyxapp" file will be repeatedly decompressed in the system's temporary directory
1759220056663

Impact

This will lead to performance degradation during the application's runtime and some unknown issues

Optimization

In the startup logic of the application, set an environment variable to record the decompression path of the "pyxapp" file. When the startup logic is triggered again, prioritize obtaining the decompression path from this environment variable to avoid further decompression operations

@EurynomeKeros
Copy link
Contributor Author

Rename the environment variables to better comply with the pyxel specification and avoid conflicts with other environment variables.It is also possible to set the environment variable as a property of pyxel, just like the "WINDOW_STATE_ENV" property, but I'm not sure if this is redundant because "app_dir" is generated by the program and should not allow users to customize it

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 this pull request may close these issues.

1 participant