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

Fix SignalConnector._has_already_handler check for callable type #10483

Merged
merged 17 commits into from
Nov 30, 2021
Merged

Fix SignalConnector._has_already_handler check for callable type #10483

merged 17 commits into from
Nov 30, 2021

Conversation

mauvilsa
Copy link
Contributor

@mauvilsa mauvilsa commented Nov 11, 2021

What does this PR do?

Fixes an issue where a user's registered SIGTERM signal handler is overwritten by SignalConnector.register_signal_handlers. One case in which this happens is when a method of a class instance is registered. That is:

import signal

class Callback:
    def __init__(self):
        signal.signal(signal.SIGTERM, self.sigterm_handler)
    def sigterm_handler(self):
        pass

callback = Callback()

The current check isinstance(signal.getsignal(signal.SIGTERM), FunctionType) evaluates to false, thus overwriting it.

No related issue. This was discussed over slack.

Does your PR introduce any breaking changes? If yes, please list them.

Before submitting

  • Was this discussed/approved via a GitHub issue? (not for typos and docs)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure your PR does only one thing, instead of bundling different changes together?
  • Did you make sure to update the documentation with your changes? (if necessary)
  • Did you write any new necessary tests? (not for typos and docs)
  • Did you verify new and existing tests pass locally with your changes?
  • Did you list all the breaking changes introduced by this pull request?
  • Did you update the CHANGELOG? (not for typos, docs, test updates, or internal minor changes/refactorings)

PR review

Anyone in the community is welcome to review the PR.
Before you start reviewing make sure you have read Review guidelines. In short, see the following bullet-list:

  • Is this pull request ready for review? (if not, please submit in draft mode)
  • Check that all items from Before submitting are resolved
  • Make sure the title is self-explanatory and the description concisely explains the PR
  • Add labels and milestones (and optionally projects) to the PR so it can be classified

Did you have fun?

Make sure you had fun coding 🙃

Copy link
Contributor

@carmocca carmocca left a comment

Choose a reason for hiding this comment

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

LGTM. Can you add a test to avoid regressions? Can be a simple unit-test. _has_already_handler can be made static for it.

@mauvilsa
Copy link
Contributor Author

Can you add a test to avoid regressions? Can be a simple unit-test.

Done.

tests/trainer/connectors/test_signal_connector.py Outdated Show resolved Hide resolved
tests/trainer/connectors/test_signal_connector.py Outdated Show resolved Hide resolved
@awaelchli awaelchli added the bug Something isn't working label Nov 12, 2021
@awaelchli awaelchli added this to the 1.5.x milestone Nov 12, 2021
mauvilsa and others added 2 commits November 12, 2021 13:39
Co-authored-by: Adrian Wälchli <aedu.waelchli@gmail.com>
@mergify mergify bot added ready PRs ready to be merged has conflicts labels Nov 12, 2021
Copy link
Contributor

@tchaton tchaton left a comment

Choose a reason for hiding this comment

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

LGTM !

@mergify mergify bot removed the has conflicts label Nov 19, 2021
@carmocca carmocca enabled auto-merge (squash) November 19, 2021 16:12
@awaelchli
Copy link
Contributor

Interesting, wasn't aware of this PR, but I have also one here #10611 where I changed the has_already_sampler to return

return signal.getsignal(signum) is not signal.SIG_DFL

Is the check for callable necessary? Which way is the correct way to check this, anyone knows? :)

@mauvilsa
Copy link
Contributor Author

Is the check for callable necessary? Which way is the correct way to check this, anyone knows? :)

I guess the callable is not necessary. What should be the behavior if the value is signal.SIG_IGN which is part of the same enum that defines signal.SIG_DFL.

@awaelchli
Copy link
Contributor

Good point, I think we should respect it and not add a handler in that case too?

@awaelchli awaelchli self-assigned this Nov 27, 2021
@mergify mergify bot removed the has conflicts label Nov 30, 2021
@codecov
Copy link

codecov bot commented Nov 30, 2021

Codecov Report

Merging #10483 (6bc06ab) into master (32e6522) will increase coverage by 45%.
The diff coverage is 100%.

❗ Current head 6bc06ab differs from pull request most recent head 6ed1213. Consider uploading reports for the commit 6ed1213 to get more accurate results

@@            Coverage Diff            @@
##           master   #10483     +/-   ##
=========================================
+ Coverage      43%      88%    +45%     
=========================================
  Files         177      177             
  Lines       16520    16506     -14     
=========================================
+ Hits         7034    14534   +7500     
+ Misses       9486     1972   -7514     

@carmocca carmocca disabled auto-merge November 30, 2021 22:17
@carmocca carmocca enabled auto-merge (squash) November 30, 2021 22:17
@carmocca carmocca merged commit f3b0a06 into Lightning-AI:master Nov 30, 2021
awaelchli added a commit that referenced this pull request Dec 1, 2021
…10483)

Co-authored-by: Adrian Wälchli <aedu.waelchli@gmail.com>
Co-authored-by: thomas chaton <thomas@grid.ai>
Co-authored-by: Carlos Mocholi <carlossmocholi@gmail.com>
lexierule pushed a commit that referenced this pull request Dec 7, 2021
…10483)

Co-authored-by: Adrian Wälchli <aedu.waelchli@gmail.com>
Co-authored-by: thomas chaton <thomas@grid.ai>
Co-authored-by: Carlos Mocholi <carlossmocholi@gmail.com>
@rohitgr7 rohitgr7 mentioned this pull request Feb 7, 2022
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ready PRs ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants