-
Notifications
You must be signed in to change notification settings - Fork 6
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
More than one logfile created when using multiprocessing ( exe built with pyinstaller) #16
Comments
Hi, could you include your log config and the name of the others 3 log files? |
Hi , yes sure. The name of the files: Thanks |
Hi, can you also include the code that you config the logger? |
Hi @Dragon2fly , apologies for the delayed reply. The setup_logging function is getting called in the following manner: It is outside the if name == "main" I will go though the mentioned issue (#5 ) to check the changes accordingly. If it still persists , I will share the reproducible code as well. Thanks for the suggestions. Will keep updated about the same. |
Hey @Dragon2fly , I have tried to integrate logger_tt into our project, oceancabbage/RimSort If you have a moment, do you think you could take a look at my implementation of your logger? All platforms have no issue with my implementation when running from source with the Python interpreter. On Linux, it behaves as expected both when run from python interpreter, and PyInstaller directly. On Windows, it behaves as expected up until I try to launch a process, and it launches the process without exception, but then some really wonky stuff happens: On MacOS, it does not launch the process which I believe is failing because of this unhandled exception. I have similar behavior to Windows with the actual log file and what appears to be happening with the logger itself, except I was actually able to get a stacktrace out of it since running a Unix executable in a terminal is actually apparently much more informative than a Windows exe from PyInstaller ;)
Perhaps it is a misconfiguration on my end? https://github.com/oceancabbage/RimSort/blob/ba71c6d746e9c9892900902de74cce6e33c57993/RimSort.py This is happening when a Here is my logger_tt config: https://github.com/oceancabbage/RimSort/blob/ba71c6d746e9c9892900902de74cce6e33c57993/data/logging_config.json Defining a port in my config does not resolve the issue on MacOS. Since Windows appears to either handle the exception, or not have it at all (it launches the process) - I am entirely unsure what is going on. But I think I might be missing something with |
Hi @twstagg, On Windows, you can open a command prompt and run your exe from there to get the error message if there is any. Anyway, from your MacOS log, I suspect that This needs further digging. But first, could you print out the child process name by using |
On Windows, I am not seeing any Unhandled Exception like I do on MacOS.
This is what I see when I run it from Python 3.9.6 interpreter. The actual log file contains the output without issue, and the game process I am launching is created successfully. You can even see the logging work in the StreamHandler to stdout that i have setup:
This is what I see after running it from PyInstaller:
It's very weird what is happening right there. The ~13 second gap you see is just because the VM I am using is laggy while it is initializing (metadata for 500 mods or so...). On real hardware, it is much snappier. |
@twstagg Thanks for your logs. I'm seeing the below line repeated 2 times in the output after
Then the So, we see that the spawned child process still had the name
|
That was from Windows. I will post some additional output from MacOS for you soon, with these new debug prints added.
Yes it is. I went ahead and put the print in both of the files that are being used here:
I am not sure how to answer this question exactly. It appears that when the application is PyInstaller'd and we are using spawn() - the If I do not have You can see where I have some of that being done here: https://github.com/oceancabbage/RimSort/blob/c0f86bd55c2219afd8e7c0c43fbbb7b0f914a18f/RimSort.py#L155-L165 In another recreation of the issue, you can see that the log even continues from that main process, after it is cut off & overwritten upon the Process being created:
|
From your description above, I understand that it opened the second GUI exactly the same as the first one even though the code is guarded with: This suggests that the Following the Could you replace the |
Correct.
Ahh! This makes sense. A quick test with similar debug prints confirms this as well.
In my Windows env, I have replaced the Pypy distributed logger-tt (latest release) with a locally cloned version of logger-tt. I did And with the prints of It appears to not be mp_main for some reason? Why is it using the namespace of the module that the Process's function was imported from...? Running from Python interpreter behaves as expected: |
@twstagg As I understanding, there are 2 problems we are facing:
We will have to solve it one by one. |
Sure thing. For science, here is output when running from Python interpreter. The process launches properly and multiprocessing works as intended. The
On MacOS, here is the PyInstaller'd output. It does not launch the process because of the Unhandled exception. Super weird compared to what we see on Windows. With this I also added an additional print for
Pretty much. I don't know why this happens when the app is frozen. When the app is running from interpreter, the log file just continues business as usual. It does not get cutoff and the process logs to the file with 0 issue using the handler.
Yeah, logger_tt crashes my Process on MacOS seemingly. The process is not spawned and subsequently the game is not launched, when the app is frozen. No issues when run from Python interpreter.
Yep! It is a mod manager for RimWorld game however, but you might be able to trick it kinda. Let me know if you have any questions:
|
Interesting development. I tried out compiling using Nuitka again, with my latest on Windows. Frozen with Nuitka, it doesn't properly detect that the executable is frozen with You can see below, the
Ultimately, the child process appears to properly spawn when compiled with Nuitka. The issue with the This makes me think there is more of an issue/limitation with Pyinstaller than I initially thought. Logger_tt is still having issue as well. What are your thoughts on this? |
Yeah, officially, I think we are ditching PyInstaller for Nuitka in light of these developments. Seeing the same improvement in frozen
Unfortunately, logger_tt still crashes the process. But it has a different With MacOS, we also see the log get corrupted/overwritten/whatever just like in Windows, and unlike Windows spawn() it does NOT launch the process (likely due to the unhandled exception): |
Hi @twstagg I don't have RimWorld installed so my environment is not the same as yours. I replaced the call to the Can you replicate it on another machine? As for the MacOS with Nuitka, from the logs you provided, it doesn't contain the line |
Hi @twstagg I added some modifications to detect child processes and print out some debug logs to
|
Hi @Dragon2fly. I think that this was more of an issue with my implementation. I've made a zillion changes to the structure of my application and am now doing things more intelligently. I just circled back to test this issue out again (with your 1.7.4 version provided above) and I don't have any of the previous issues on MacOS at least. Testing on Windows here soon as well. Thanks for your response and discussion! I'll let you know if I run into more issues. |
Ah, yes, on Windows the issue is still present with the log starting over and zeroing. I don't see the same debug prints that you added on Windows that I do in MacOS though... |
Hi @twstagg. Have you had any progress on Windows yet? Since the problem was resolved on MacOS, I'm going to officially release v1.7.4 to PyPI. |
@Dragon2fly I wanted to let you know that as of today i sorted out my stupidity This commit is what fixed all of my issues. The logger setup was getting executed on re-import. Idk what i was thinking before. Thank you very much for your time and for the awesome piece of software btw! |
Hello.
I am using logger_tt module with python code having multiprocessing approach in windows environment. While running the code from python interpreter , one logfile is created as expected.
But when I build the exe ( using pyinstaller) and execute it using a windows command prompt , number of logfile created are more than one. I am creating three processes, and the four logfiles are created.
Though only one logfile contains all the logs (including print, etc..). The other logfiles created just contains following text (with different time stamps) :
[2022-11-02 10:58:44] [root:190 DEBUG] New log started_
[2022-11-02 10:58:44] [root:191 DEBUG] Log config file: configs\log_config.json
The text was updated successfully, but these errors were encountered: