Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
satella
Manage
Activity
Members
Labels
Plan
Issues
1
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
public
satella
Commits
d90a38b6
Commit
d90a38b6
authored
8 years ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
liek a boss
parent
e33d4fe3
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
satella/posix/signals.py
+41
-15
41 additions, 15 deletions
satella/posix/signals.py
with
41 additions
and
15 deletions
satella/posix/signals.py
+
41
−
15
View file @
d90a38b6
...
...
@@ -6,33 +6,59 @@ from __future__ import print_function, absolute_import, division
import
six
import
signal
import
logging
import
time
from
threading
import
Lock
from
satella.coding
import
typed
logger
=
logging
.
getLogger
(
__name__
)
end
=
False
def
__sighandler
(
a
,
b
):
global
end
end
=
True
@typed
(
list
)
def
hang_until_sig
(
extra_signals
=
[]):
"""
Will hang until this process receives SIGTERM or SIGINT.
If you pass extra signal IDs (signal.SIG*) with extra_signals,
then also on those signals this call will release.
"""
me_lock
=
Lock
()
me_lock
.
acquire
()
def
insignum
(
sig
):
def
o
(
sigq
,
frame
):
if
sig
!=
sigq
:
logger
.
warning
(
'
Handler for signal %s responded for signal %s
'
,
sig
,
sigq
)
else
:
logger
.
warning
(
'
Received signal %s
'
,
sigq
)
me_lock
.
release
()
return
o
global
end
for
s
in
extra_signals
+
[
signal
.
SIGTERM
,
signal
.
SIGINT
]:
signal
.
signal
(
s
,
insignum
(
s
))
# Ascertain what Python are we working on. 2012 PyPy and earlier
# may be affected by https://bugs.pypy.org/issue1255
bugged_pypy
=
False
try
:
me_lock
.
acquire
()
except
KeyboardInterrupt
:
import
platform
except
:
pass
else
:
if
platform
.
python_implementation
()
==
'
PyPy
'
:
try
:
mon
,
day
,
year
=
platform
.
python_build
()[
1
].
split
(
'
'
)
year
=
int
(
year
)
except
:
pass
else
:
bugged_pypy
=
year
<=
2012
signal
.
signal
(
signal
.
SIGTERM
,
__sighandler
)
signal
.
signal
(
signal
.
SIGINT
,
__sighandler
)
for
s
in
extra_signals
:
signal
.
signal
(
s
,
__sighandler
)
while
not
end
:
try
:
if
bugged_pypy
:
time
.
sleep
(
1
)
# see https://bugs.pypy.org/issue1255
else
:
signal
.
pause
()
except
:
# pause() is undefined on Windows
try
:
# we will sleep for small periods of time
time
.
sleep
(
0.5
)
except
IOError
:
# "Interrupted system call"
pass
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment