-
Notifications
You must be signed in to change notification settings - Fork 992
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
Gracefully shutdown if SIGINT was sent in TUI mode #2784
Conversation
It is needed for p2p thread management, currently there is no point where we could store thread handles and join themm because thread::join consume the caller, which is impossible in case of Arc. Also we don't need to check running flag constantly and it's easier to reason about the state.
@@ -101,13 +101,8 @@ impl Server { | |||
} | |||
} | |||
|
|||
info_callback(serv.clone()); | |||
loop { |
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.
lol
let running = Arc::new(AtomicBool::new(true)); | ||
let _ = thread::Builder::new() | ||
.name("ui".to_string()) | ||
.spawn(move || { |
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.
So we now run the TUI in the main thread and not in a separate ui thread?
Is there any downside to this?
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.
It's symmetrical with non-tui case. Also to be fair I'm not sure, it seems that cursive
creates a separate thread anyway, but I'm not an expert. What I see is that SIGINT is magically handled (in ncurses backend or most likely in C code, because I didn't find any traces of it in cursive
) and it stops only UI, so we are able to call server.stop()
in the main thread after that.
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.
👍
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.
👍
Fixes #2799
Also 2 Arc's were replaced by one server's instance.
It is needed for p2p thread management in #2778, currently there is no point where we could store thread handles and join them because
thread::join
consume the caller, which is impossible in case of Arc.