-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[PENDING] Manual interruption #281
Comments
I came across this bug on Ubuntu this morning as well. I ran Do you think this is related to #200? |
It is not related to #200. In the case of I can't reproduce this under normal search operation though (on Linux). I'll need to explicitly try it on Windows. |
|
I would like to remove the
All told, my feeling is that getting the color reset handling right just isn't worth it. If you run into the problem, it's easy to fix by simply running:
cc @lambda |
This effect is kinda unfortunate. Triggered it the first time I tried rg. FYI: Calling |
I understand it is unfortunate. I'm open to better ideas. |
Perhaps a silly question, but can't you just have an atexit handler that always resets colors, and the ctrl-c just ensures regular processing is interrupted s. t. exit() is called (after releasing any resources)? |
@seabadger Could you address this particular point from my comment above?
In particular, this is exactly the problem:
(FYI, |
First -- a disclaimer: I may be coming at this from the point of ignorance, as (1) I've just discovered this project and only looked at small parts of the code so far, (2) don't know Rust so may be missing something even for the parts that I did look at, and (3) don't know what solutions were already considered and discarded beyond the one in this issue. So my apologies if I'm mentioning something obvious and/or obviously wrong. That said: if I understood correctly, the implementation that was removed by commit de5cb7d did the work (cleanup + exit) directly in the signal handler, which indeed required this kind of synchronization. Would it be feasible to instead defer the actual work to a safer point? This assumes:
Hope I didn't miss something glaringly obvious... (and you're right about |
Thanks for the ideas!
Right. This is what the "there must be some kind of synchronization between printing to stdout and resetting the terminal" part is about. It would have to be pushed all the way down into the input buffer handling itself. It would not be nice, and I can almost guarantee that it will be a source of bugs of the form "I hit |
(To be fair, a large recursive grep or 'find | xargs grep' would not necessarily respond to Control-C instantaneously (speaking from experience) -- so at least from the user's perspective, I think I would find this acceptable; can't speak for others, of course. But the effect on the code structure remains, so here I'll defer to you) How about another approach that (I think) addresses both issues: a wrapper.
The parent's signal handler would simply pass the signal on to the child process. The child process should behave exactly as rg behaves today. Cons:
Pros:
|
@seabadger Hmmmmmmmm..... I like that. I can't immediately think of a counter-argument to that. My only caveat is that it would be nice if it worked on Windows, although I suppose it wouldn't have to be a hard requirement. (It could be something that only works on Unixish systems.) |
One other point: I don't have good intuition as to the overhead of a single |
@BurntSushi After a brief look at code what i can see is that std get locked once rg runs in one thread. Is it actually necessary to lock stdout in one thread runner? |
@DoumanAsh Could you please read this thread? I think the current best solution is a fork-exec that was written up here #281 (comment) --- I just don't know if it works on Windows.
Yes. Locking |
@BurntSushi I started implementing with It is rather difficult to detect whether you are invoked by user or yourself unless i specify some hidden option. |
@DoumanAsh Yeah, a hidden flag my unfortunately be necessary. |
Is it possible to find out the name of your parent process? If so, that might be an alternative to a hidden option (ot equivalently hidden environment variable) |
@seabadger I'm not aware of any way. The only thing we can reliable to find is zero argument of our process (name of binary or how it has been started) but if you have any hints...? UPD: But we could start Command with special environment variable which actually might be better |
@seabadger I went with setting particular environment variable. It should reliable enough for us to use as chance of collision is pretty small. PR #281 |
The child process sounds like a nice solution, but it's kind of a big hammer for a small problem. Why not just ignore the lock on stdout and write the terminal color reset code directly to fd 1? |
If that actually works, then I would be okay with it. termcolor would need
to support that type of access directly. The fundamental problem is that
your solution isn't actually guaranteed to work.
…On Apr 10, 2017 2:26 AM, "jethrogb" ***@***.***> wrote:
The child process sounds like a nice solution, but it's kind of a big
hammer for a small problem. Why not just ignore the lock on stdout and
write the terminal color reset directly to fd 1?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#281 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAb34ki_oLPcNORhtkj2T7bZz5N1FA9iks5rucuIgaJpZM4LNnaR>
.
|
@jethrogb Your solution would not work because, at least on windows, your handler of Crtl-C is called in a separate thread(from main thread) and it is highly likely that main thread is able to print some more colors before being actually terminated |
@DoumanAsh I think @jethrogb's proposal relies on it not being likely that the main thread will print more colors. That's what I meant by "it's not guaranteed to work." However, it may work well in practice. The vast majority of printer execution is spent writing the actual results, and not tweaking the color configuration. (In any case, Windows is a red herring. I imagine @jethrogb's fix would work equally well on both Unix and Windows.) |
We discussed a quit flag before, I think that idea was shot down because the lock is being held somewhere high up the call chain, but if we only care about "not printing" and not about "releasing the lock", maybe using a quit flag is ok again. Alternatively, you can call TerminateThread/pthread_kill on all other threads in the signal handler. |
Issue was created about 0.3.2, tested 0.5.2 right now, still not fixed alas. |
The original bug is fixed because ripgrep no longer does ^C handling. |
Steps to reproduce:
|
I've finally gotten a chance to test this on Windows and this is definitely fixed. I can |
FYI, the saga continues, see #2727 - now with even more syscalls! :) |
Let’s launch
rg.exe 1
and… What a colossal, incessant output!But how could one interrupt the process assuming the launch was a mistake?
Ctrl+C in Windows is the expected way to go. But it does NOT work now.
The text was updated successfully, but these errors were encountered: