-
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
Second app logs to log file of first app while first app running - Windows #21
Comments
Hi @1marc1 Because the SO_REUSEADDR option is set on the logging socket server, So to run multiple independent multi-processing applications with logging at the same time, You could set the port directly in the
Of course, the port number must not be already used by other applications. |
Thank you so much for your continued support. I upgraded to logger_tt 1.7.3 and set the port number. It now works as expected! |
Further to my comment, it is particularly evident when adding the statement |
Hi @1marc1 TLDR: Daemon thread (not recommended):
This will cause the main thread to exit immediately, even if there may be a log waiting to be sent to the logger thread. Set the connection timeout to 1:
This works well assuming all the necessary logs from the main process's main thread and child processes are sent to the logger thread within 1 second. |
Hi @Dragon2fly, I have been running some test on Linux, using logger_tt 1.7.3. Here are the results. When not specifying a port number in setup_logging or when specifying port number 9020, when I run
When I set the connection timeout to 1 and I don't specify the port (or I specify it as 9020), the results are similar:
When I use the not recommended daemon thread and either don't specify the port number or set it to 9020, then this is the result:
We can see that with the daemon thread the command prompt is returned quickly. However, with the daemon thread, the App2 is doing stuff message does not end up in the log file. FWIW, if I use both the daemon thread and the connection timeout, the behavior is like specifying only the daemon thread: the application exists quickly and the message does not appear in the log. The results are the same when I specify a completely different port such as 6789. |
Hi @1marc1 , Sorry, I forgot to mention that you need to comment out the below line for it to work. Line 313 in ef5a97d
Please test again. If there is no other problem, I'll push it into the next version.
Yeah, you've just confirmed that the |
Thanks @Dragon2fly, after commenting out that line it all seems to work, but you have to specify the connection timeout lines in app2.py. It then doesn't seem to matter if you specify a port or not. In my testing I (a) did not specify a port, (b) specified port 9020, (c) specified port 9021 and (d) specified port 6789. In all instances the App2 is doing stuff message shows up in the log file and the typical result is this:
Now, if I leave the following lines out of app2.py, then the application does not exit at all and seems to be stuck. I pressed CTRL+C after 40 seconds to terminate the application.
If I change line 313 of core.py to self.connection.settimeout(1) and I don't include the two lines (above) for the connection timeout, then the message makes it to the log and the typical output is:
Not sure what the best way is to further update your code, but based on these (limited) results, it seems that the best approach would be to update line 313 of core.py as it will not require the program using logger_tt to implement the connection timeout. However, I don't know if there are other implications to changing line 313. |
Hi @1marc1
There are 2 separate things here.
After the socket is closed, the The SO_REUSEADDR option is used to ensure that when you restart the app, it can instantly reuse the same That being said, the SO_REUSEADDR option doesn't behave the same on all platforms regarding two or more sockets binding to the same
So, not setting the port and getting the log message to the right file is really a hit or a miss.
Changing line 313 is fine. It has the same effect as adding the 2 lines that you tried. |
Cool. I am keen to see your updates implemented! |
Symptoms:
I am using logger_tt version 1.5 on Python 3.9. This happens in a Windows environment only. When running on Linux, app2.py will always log to app2.log, even when app1.py is running.
Below is a minimal example that illustrates the issue. It is to be said that in my actual programs I am using multi-processing and multi-threading. There is also shared code between the actual programs that uses the logging facility.
The contents of log_config.json are as follows:
The text was updated successfully, but these errors were encountered: