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

Fixed daemon detection to determine forking behavior #3140

Merged
merged 2 commits into from
Sep 17, 2024

Conversation

sammywachtel
Copy link
Contributor

Introduced the is_daemon_process function in utils/system.py to determine if the current process is a daemon. Updated the logic in constants.py to use this new utility function for determining forking behavior.

Introduced the `is_daemon_process` function in `utils/system.py` to determine if the current process is a daemon. Updated the logic in `constants.py` to use this new utility function for determining forking behavior.
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@sammywachtel sammywachtel marked this pull request as ready for review September 16, 2024 22:40
@izeigerman
Copy link
Member

Hey @sammywachtel ! Thanks a lot for your submission. Can you please provide a little more context around the issue you ran into with the existing implementation and how the new approach is better.

:rtype: bool
"""

return not os.isatty(sys.stdout.fileno())
Copy link
Member

@izeigerman izeigerman Sep 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't you just do:

sys.stdout.isatty()

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @izeigerman. I believe there's a risk of getting an AttributeError in some cases when the underlying file descriptor doesn't implement isatty(). Or if the stdout is in a wrapper that doesn't correctly implement isatty(). Anyway, it feels like best practice. It would work most of the time with just sys.stdout.isatty(), though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As for your question about why the change: I am working with the airflow integration and after one of the recent new versions (I was on 0.18.0 I think) I started getting errors surrounding the worker settings. I noticed the code in constants.py had a recent change that was supposed restrict the number of workers to 1 when in an airflow environment, but the check for the process being within a daemon was using the multiprocessing package which would only return a "true" if the daemon were a multiprocessing package daemon. It doesn't appear to be that way with airflow, but rather, it's using a standard system daemon for which there's no built-in check. I hope that helps!

This change eliminates the `system.py` file and integrates the `is_daemon_process` function into `constants.py`.
@tobymao
Copy link
Contributor

tobymao commented Sep 16, 2024

@sammywachtel please sign the cla, thank you!

@sammywachtel
Copy link
Contributor Author

@sammywachtel please sign the cla, thank you!

It is signed, but for some reason still shows up as pending.

@tobymao tobymao merged commit f7e4c47 into TobikoData:main Sep 17, 2024
19 of 20 checks passed
@sammywachtel sammywachtel deleted the fix/airflow-daemon-detect branch September 17, 2024 13:17
tobymao added a commit that referenced this pull request Sep 17, 2024
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.

4 participants