Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
software-di-controllo
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Davide Ricci
software-di-controllo
Commits
af3ce544
Commit
af3ce544
authored
2 months ago
by
vertighel
Browse files
Options
Downloads
Patches
Plain Diff
Again pause, resume etc
parent
48dde1ae
No related branches found
No related tags found
No related merge requests found
Pipeline
#29033
passed
2 months ago
Stage: setup_and_format
Stage: lint
Stage: auto_commit
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
noctua/sequencer.py
+14
-12
14 additions, 12 deletions
noctua/sequencer.py
with
14 additions
and
12 deletions
noctua/sequencer.py
+
14
−
12
View file @
af3ce544
...
...
@@ -34,9 +34,8 @@ class Sequencer():
self
.
params
=
{}
# The parameters of the running template
self
.
quitting
=
False
self
.
embedded
=
embedded
# To manage sys.exit if called alone
self
.
original_sigint
=
signal
.
getsignal
(
signal
.
SIGINT
)
# Store original
signal
.
signal
(
signal
.
SIGINT
,
self
.
interrupt
)
self
.
original_sigint
=
signal
.
getsignal
(
signal
.
SIGINT
)
# Store original
def
load_script
(
self
,
template_script_path
,
params
=
{}):
'''
Load a python file where the template is implemented
'''
...
...
@@ -186,23 +185,22 @@ class Sequencer():
datetime
.
utcnow
()
-
now
).
total_seconds
()
:
.
3
f
}
s
"
)
def
interrupt
(
self
):
def
interrupt
(
self
,
signum
,
frame
):
'''
Intercept a CTRL+C instead of raising a KeyboardInterrupt exception
in order to be able to operate on the template class, for
example to modify a pause attribute or call a method.
'''
# Temporarily restore original handler to avoid nested inputs if Ctrl+C
# is hit again
signal
.
signal
(
signal
.
SIGINT
,
self
.
original_sigint
)
#
signal.signal(signal.SIGINT, self.original_sigint)
try
:
# Use a more robust way to get input that doesn't interfere with
# logging as much
# THIS IS WHERE THE MENU SHOULD BE PRINTED
sys
.
stderr
.
write
(
"
\n
--- INTERRUPT ---
\n
"
)
sys
.
stderr
.
write
(
"
(P)ause, (R)esume, (T)ry again paragraph, (N)ext template, (Q)uit:
\n
"
)
sys
.
stderr
.
write
(
"
(P)ause, (R)esume, (T)ry again paragraph, (N)ext template, (Q)uit:
\n
"
)
sys
.
stderr
.
flush
()
answer
=
sys
.
stdin
.
readline
().
strip
().
lower
()
# Read directly from stdin
answer
=
sys
.
stdin
.
readline
().
strip
().
lower
()
if
answer
.
startswith
(
'
p
'
):
self
.
pause
()
...
...
@@ -226,9 +224,13 @@ class Sequencer():
os
.
_exit
(
1
)
# Force exit if not embedded
else
:
self
.
quit
()
# Attempt graceful quit if embedded
# except Exception as e: # Add a broad catch here for debugging
# sys.stderr.write(f"ERROR IN INTERRUPT HANDLER: {type(e).__name__}: {e}\n")
# log.error("Error in interrupt handler", exc_info=True)
# # Fallback to quitting if the handler itself fails
# self.quit()
finally
:
# Re-hook our custom interrupt handler
signal
.
signal
(
signal
.
SIGINT
,
self
.
interrupt
)
signal
.
signal
(
signal
.
SIGINT
,
self
.
interrupt
)
# Re-hook
def
pause
(
self
):
'''
...
...
This diff is collapsed.
Click to expand it.
Davide Ricci
@davide.ricci
mentioned in commit
5b63ad17
·
2 months ago
mentioned in commit
5b63ad17
mentioned in commit 5b63ad172ba348e8dec9310c90587bf0da43fc78
Toggle commit list
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