-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
Updater: Log info message when receiving signal #951
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6aa9b89
Updater: Log info message when receiving signal
Makman2 dcbf6b4
Add @Makman2 to contributors
Makman2 35d47b8
Use pytest-capturelog instead of testfixtures
Makman2 eb4b151
Fix test_idle() with caplog
tsnoam 508c5c4
Fix pytest warnings by switching to pytest-catchlog
tsnoam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,5 @@ yapf | |
pre-commit | ||
beautifulsoup4 | ||
pytest | ||
pytest-capturelog | ||
pytest-timeout |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,9 +16,11 @@ | |
# | ||
# You should have received a copy of the GNU Lesser Public License | ||
# along with this program. If not, see [http://www.gnu.org/licenses/]. | ||
import logging | ||
import os | ||
import signal | ||
import sys | ||
from functools import partial | ||
from queue import Queue | ||
from random import randrange | ||
from threading import Thread | ||
|
@@ -238,15 +240,25 @@ def _send_webhook_msg(self, | |
|
||
return urlopen(req) | ||
|
||
def signal_sender(self): | ||
def signal_sender(self, updater): | ||
sleep(0.2) | ||
while not updater.running: | ||
sleep(0.2) | ||
|
||
os.kill(os.getpid(), signal.SIGTERM) | ||
|
||
@signalskip | ||
def test_idle(self, updater): | ||
def test_idle(self, updater, caplog): | ||
updater.start_polling(0.01) | ||
Thread(target=self.signal_sender).start() | ||
updater.idle() | ||
Thread(target=partial(self.signal_sender, updater=updater)).start() | ||
|
||
with caplog.atLevel(logging.INFO): | ||
updater.idle() | ||
|
||
rec = caplog.records()[-1] | ||
assert rec.msg.startswith('Received signal {}'.format(signal.SIGTERM)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just curious, why not asserting for the complete message? :) |
||
assert rec.levelname == 'INFO' | ||
|
||
# If we get this far, idle() ran through | ||
sleep(.5) | ||
assert updater.running is False | ||
|
@@ -260,7 +272,7 @@ def user_signal_inc(signum, frame): | |
|
||
updater.user_sig_handler = user_signal_inc | ||
updater.start_polling(0.01) | ||
Thread(target=self.signal_sender).start() | ||
Thread(target=partial(self.signal_sender, updater=updater)).start() | ||
updater.idle() | ||
# If we get this far, idle() ran through | ||
sleep(.5) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpicking here. the
reversed
&sorted
are useless here as you're creating a dict. please remove them.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the
sorted
was there for signals with different names but same number, so there's a deterministic outcome. However I haven't understood thereversed
call too^^There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And kk
reversed
then picks signal names that are sorted at the beginning. On my system I get these differences when I don't usereversed
:Though not sure if it's that important here^^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check manpage of
signal(7)
all the above are synonyms. If one name is chosen over another it's merely a matter of luck, as dictionary order is not guaranteed.On my system I had different results on different executions.
Another option is to leave the signal name alone and just print the number.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like it's true, I'm just wondering: the order we iterate over should always produce a guaranteed outcome.
vars(signal).items()
has unique mappings fromname -> number
. Usingsorted
we get always the same list with the same order, and then we are filling the dict with those values, while switchingname
andnumber
. If there are numbers that are equal, later elements in the list should overwrite the old ones. Although using dict-comprehension, citing thedict
-docs:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't do that, signal numbers differ on OSes for the "same" signals. I think people identify those signals usually by their name, like
SIGINT
/SIGTERM
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok. not worth the argument, lets keep it as is.