FAQ
Hi,

There are many use cases when you have to interrupt go func()
{io.Copy(dst,src)}(). I've googled but still didn't find any solution on
how to implement that.

In my case I close writer: myWriter.Close() at the end of function,
but io.Copy(myWriter,os.Stdin) still works. Don't know how to interrupt it.

Thanks in advance.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Manlio Perillo at Apr 13, 2016 at 4:44 pm
    Il giorno mercoledì 13 aprile 2016 18:00:00 UTC+2, kay ru ha scritto:
    Hi,

    There are many use cases when you have to interrupt go func()
    {io.Copy(dst,src)}(). I've googled but still didn't find any solution on
    how to implement that.
    You can not interrupt a goroutine like you can interrupt, as an example, a
    process.

    In my case I close writer: myWriter.Close() at the end of function,
    but io.Copy(myWriter,os.Stdin) still works. Don't know how to interrupt it.
    Can you post your code?
    This, as an example, works as expected:
    https://play.golang.org/p/U9zUR9LkD8

    It prints on stderr:
    Copy(): 0 bytes copied, write /dev/stdout: bad file descriptor

    Note that in my example I close Stdout from a *different* goroutine.
    Also note that the code I posted is probably not concurrent safe: there are
    better methods to interrupt a goroutine, but they require special coding
    for synchronization.


    Manlio

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Konstantin Khomoutov at Apr 13, 2016 at 4:45 pm

    On Wed, 13 Apr 2016 08:50:01 -0700 (PDT) kay ru wrote:

    There are many use cases when you have to interrupt go func()
    {io.Copy(dst,src)}(). I've googled but still didn't find any solution
    on how to implement that.

    In my case I close writer: myWriter.Close() at the end of function,
    but io.Copy(myWriter,os.Stdin) still works. Don't know how to
    interrupt it.
    io.Copy should stop if either of the two conditions hold:

    * The nearest read from `src` hits the EOF condition or other error.

    * The nearest write to `dst` hits the error.

    Hence it might be an error in the implementation of myWriter since it
    might not signal io.ErrShortWrite (or io.ErrClosedPipe) to the client
    when a write is attempted to it after it was closed.

    Another case I might fathom is the case of your writer being os.Stdout
    or os.Stderr, and the possible resulting interaction with the EPIPE
    errors and the SIGPIPE signal.

    I'd say we need more details including your OS and Go version.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Zippoxer at Apr 13, 2016 at 5:03 pm
    Make your own Copy method that can be interrupted. Let me know if you want
    a snippet.
    On Wednesday, April 13, 2016 at 7:00:00 PM UTC+3, kay ru wrote:

    Hi,

    There are many use cases when you have to interrupt go func()
    {io.Copy(dst,src)}(). I've googled but still didn't find any solution on
    how to implement that.

    In my case I close writer: myWriter.Close() at the end of function,
    but io.Copy(myWriter,os.Stdin) still works. Don't know how to interrupt it.

    Thanks in advance.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Konstantin Khomoutov at Apr 13, 2016 at 5:26 pm

    On Wed, 13 Apr 2016 10:03:32 -0700 (PDT) Zippoxer wrote:

    Make your own Copy method that can be interrupted. Let me know if you
    want a snippet.
    I wonder how would you implement one taking into account that either
    reading from `src` or writing to `dst` might legitimately sleep in a
    syscall -- blocking the host OS thread.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Zippoxer at Apr 13, 2016 at 10:30 pm
    You could only stop read and writing chunks once you received a cancel
    signal. This has the advantage of the copy exiting right after it's current
    read or write operation.
    You cannot interrupt a single read or write operation as far as I know,
    unless the reader/writer allows you similarly to net.Conn's Close.

    On Wednesday, April 13, 2016 at 8:26:25 PM UTC+3, Konstantin Khomoutov
    wrote:
    On Wed, 13 Apr 2016 10:03:32 -0700 (PDT)
    Zippoxer <zipp...@gmail.com <javascript:>> wrote:
    Make your own Copy method that can be interrupted. Let me know if you
    want a snippet.
    I wonder how would you implement one taking into account that either
    reading from `src` or writing to `dst` might legitimately sleep in a
    syscall -- blocking the host OS thread.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Kay ru at Apr 14, 2016 at 7:34 am
    Sure, I'd see how should it look like.
    On Wednesday, April 13, 2016 at 7:03:32 PM UTC+2, Zippoxer wrote:

    Make your own Copy method that can be interrupted. Let me know if you want
    a snippet.
    On Wednesday, April 13, 2016 at 7:00:00 PM UTC+3, kay ru wrote:

    Hi,

    There are many use cases when you have to interrupt go func()
    {io.Copy(dst,src)}(). I've googled but still didn't find any solution on
    how to implement that.

    In my case I close writer: myWriter.Close() at the end of function,
    but io.Copy(myWriter,os.Stdin) still works. Don't know how to interrupt it.

    Thanks in advance.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Kay ru at Apr 14, 2016 at 7:00 pm
    Looks like it is possible to implement something like "readerCloser :=
    ioutil.NopCloser(os.Stdin)" which could be closed. But even when call
    readerCloser.Close() it still doesn't work as expected and you have to type
    something in console manually.
    On Wednesday, April 13, 2016 at 7:03:32 PM UTC+2, Zippoxer wrote:

    Make your own Copy method that can be interrupted. Let me know if you want
    a snippet.
    On Wednesday, April 13, 2016 at 7:00:00 PM UTC+3, kay ru wrote:

    Hi,

    There are many use cases when you have to interrupt go func()
    {io.Copy(dst,src)}(). I've googled but still didn't find any solution on
    how to implement that.

    In my case I close writer: myWriter.Close() at the end of function,
    but io.Copy(myWriter,os.Stdin) still works. Don't know how to interrupt it.

    Thanks in advance.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Skip Tavakkolian at Apr 14, 2016 at 7:54 pm
    perhaps you could use timeouts to abandon reads that take too long. here's
    a timed copy:

    https://gist.github.com/9nut/b874afee6a3cae629c9adc689d195884

    so long as there's keyboard input (terminated by newline) it will loop;
    otherwise it times out. closing stdin before timeout also works.
    On Thu, Apr 14, 2016 at 12:00 PM, kay ru wrote:

    Looks like it is possible to implement something like "readerCloser :=
    ioutil.NopCloser(os.Stdin)" which could be closed. But even when call
    readerCloser.Close() it still doesn't work as expected and you have to type
    something in console manually.
    On Wednesday, April 13, 2016 at 7:03:32 PM UTC+2, Zippoxer wrote:

    Make your own Copy method that can be interrupted. Let me know if you
    want a snippet.
    On Wednesday, April 13, 2016 at 7:00:00 PM UTC+3, kay ru wrote:

    Hi,

    There are many use cases when you have to interrupt go func()
    {io.Copy(dst,src)}(). I've googled but still didn't find any solution on
    how to implement that.

    In my case I close writer: myWriter.Close() at the end of function,
    but io.Copy(myWriter,os.Stdin) still works. Don't know how to interrupt it.

    Thanks in advance.
    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Kay ru at Apr 15, 2016 at 12:52 pm
    Your solution doesn't work. You have to type enter in the terminal. Test is
    here:

    http://play.golang.org/p/pnFctQa-Zl

    On Thursday, April 14, 2016 at 9:54:23 PM UTC+2, Skip wrote:

    perhaps you could use timeouts to abandon reads that take too long.
    here's a timed copy:

    https://gist.github.com/9nut/b874afee6a3cae629c9adc689d195884

    so long as there's keyboard input (terminated by newline) it will loop;
    otherwise it times out. closing stdin before timeout also works.

    On Thu, Apr 14, 2016 at 12:00 PM, kay ru <kay....@gmail.com <javascript:>>
    wrote:
    Looks like it is possible to implement something like "readerCloser :=
    ioutil.NopCloser(os.Stdin)" which could be closed. But even when call
    readerCloser.Close() it still doesn't work as expected and you have to type
    something in console manually.
    On Wednesday, April 13, 2016 at 7:03:32 PM UTC+2, Zippoxer wrote:

    Make your own Copy method that can be interrupted. Let me know if you
    want a snippet.
    On Wednesday, April 13, 2016 at 7:00:00 PM UTC+3, kay ru wrote:

    Hi,

    There are many use cases when you have to interrupt go func()
    {io.Copy(dst,src)}(). I've googled but still didn't find any solution on
    how to implement that.

    In my case I close writer: myWriter.Close() at the end of function,
    but io.Copy(myWriter,os.Stdin) still works. Don't know how to interrupt it.

    Thanks in advance.
    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts...@googlegroups.com <javascript:>.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • C Banning at Apr 15, 2016 at 1:33 pm
    stdin buffers for a NL (Enter) key stroke unless it's in raw mode
    On Friday, April 15, 2016 at 7:52:41 AM UTC-5, kay ru wrote:

    Your solution doesn't work. You have to type enter in the terminal. Test
    is here:

    http://play.golang.org/p/pnFctQa-Zl

    On Thursday, April 14, 2016 at 9:54:23 PM UTC+2, Skip wrote:

    perhaps you could use timeouts to abandon reads that take too long.
    here's a timed copy:

    https://gist.github.com/9nut/b874afee6a3cae629c9adc689d195884

    so long as there's keyboard input (terminated by newline) it will loop;
    otherwise it times out. closing stdin before timeout also works.
    On Thu, Apr 14, 2016 at 12:00 PM, kay ru wrote:

    Looks like it is possible to implement something like "readerCloser :=
    ioutil.NopCloser(os.Stdin)" which could be closed. But even when call
    readerCloser.Close() it still doesn't work as expected and you have to type
    something in console manually.
    On Wednesday, April 13, 2016 at 7:03:32 PM UTC+2, Zippoxer wrote:

    Make your own Copy method that can be interrupted. Let me know if you
    want a snippet.
    On Wednesday, April 13, 2016 at 7:00:00 PM UTC+3, kay ru wrote:

    Hi,

    There are many use cases when you have to interrupt go func()
    {io.Copy(dst,src)}(). I've googled but still didn't find any solution on
    how to implement that.

    In my case I close writer: myWriter.Close() at the end of function,
    but io.Copy(myWriter,os.Stdin) still works. Don't know how to interrupt it.

    Thanks in advance.
    --
    You received this message because you are subscribed to the Google
    Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send
    an email to golang-nuts...@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Kay ru at Apr 15, 2016 at 1:35 pm
    And how to avoid this buffering?
    On Friday, April 15, 2016 at 3:33:03 PM UTC+2, C Banning wrote:

    stdin buffers for a NL (Enter) key stroke unless it's in raw mode
    On Friday, April 15, 2016 at 7:52:41 AM UTC-5, kay ru wrote:

    Your solution doesn't work. You have to type enter in the terminal. Test
    is here:

    http://play.golang.org/p/pnFctQa-Zl

    On Thursday, April 14, 2016 at 9:54:23 PM UTC+2, Skip wrote:

    perhaps you could use timeouts to abandon reads that take too long.
    here's a timed copy:

    https://gist.github.com/9nut/b874afee6a3cae629c9adc689d195884

    so long as there's keyboard input (terminated by newline) it will loop;
    otherwise it times out. closing stdin before timeout also works.
    On Thu, Apr 14, 2016 at 12:00 PM, kay ru wrote:

    Looks like it is possible to implement something like "readerCloser :=
    ioutil.NopCloser(os.Stdin)" which could be closed. But even when call
    readerCloser.Close() it still doesn't work as expected and you have to type
    something in console manually.
    On Wednesday, April 13, 2016 at 7:03:32 PM UTC+2, Zippoxer wrote:

    Make your own Copy method that can be interrupted. Let me know if you
    want a snippet.
    On Wednesday, April 13, 2016 at 7:00:00 PM UTC+3, kay ru wrote:

    Hi,

    There are many use cases when you have to interrupt go func()
    {io.Copy(dst,src)}(). I've googled but still didn't find any solution on
    how to implement that.

    In my case I close writer: myWriter.Close() at the end of function,
    but io.Copy(myWriter,os.Stdin) still works. Don't know how to interrupt it.

    Thanks in advance.
    --
    You received this message because you are subscribed to the Google
    Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send
    an email to golang-nuts...@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • C Banning at Apr 15, 2016 at 1:47 pm
    Your program has to set the terminal in "raw" mode - "man stty" should help.
    On Friday, April 15, 2016 at 8:35:10 AM UTC-5, kay ru wrote:

    And how to avoid this buffering?
    On Friday, April 15, 2016 at 3:33:03 PM UTC+2, C Banning wrote:

    stdin buffers for a NL (Enter) key stroke unless it's in raw mode
    On Friday, April 15, 2016 at 7:52:41 AM UTC-5, kay ru wrote:

    Your solution doesn't work. You have to type enter in the terminal. Test
    is here:

    http://play.golang.org/p/pnFctQa-Zl

    On Thursday, April 14, 2016 at 9:54:23 PM UTC+2, Skip wrote:

    perhaps you could use timeouts to abandon reads that take too long.
    here's a timed copy:

    https://gist.github.com/9nut/b874afee6a3cae629c9adc689d195884

    so long as there's keyboard input (terminated by newline) it will loop;
    otherwise it times out. closing stdin before timeout also works.
    On Thu, Apr 14, 2016 at 12:00 PM, kay ru wrote:

    Looks like it is possible to implement something like "readerCloser :=
    ioutil.NopCloser(os.Stdin)" which could be closed. But even when call
    readerCloser.Close() it still doesn't work as expected and you have to type
    something in console manually.
    On Wednesday, April 13, 2016 at 7:03:32 PM UTC+2, Zippoxer wrote:

    Make your own Copy method that can be interrupted. Let me know if you
    want a snippet.
    On Wednesday, April 13, 2016 at 7:00:00 PM UTC+3, kay ru wrote:

    Hi,

    There are many use cases when you have to interrupt go func()
    {io.Copy(dst,src)}(). I've googled but still didn't find any solution on
    how to implement that.

    In my case I close writer: myWriter.Close() at the end of function,
    but io.Copy(myWriter,os.Stdin) still works. Don't know how to interrupt it.

    Thanks in advance.
    --
    You received this message because you are subscribed to the Google
    Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send
    an email to golang-nuts...@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Kay ru at Apr 15, 2016 at 1:55 pm
    Too hacky. There should be a way to interrupt Read. It is interrupted when
    you exit the process, so I hope there should be possibility to do that
    manually.
    On Friday, April 15, 2016 at 3:47:31 PM UTC+2, C Banning wrote:

    Your program has to set the terminal in "raw" mode - "man stty" should
    help.
    On Friday, April 15, 2016 at 8:35:10 AM UTC-5, kay ru wrote:

    And how to avoid this buffering?
    On Friday, April 15, 2016 at 3:33:03 PM UTC+2, C Banning wrote:

    stdin buffers for a NL (Enter) key stroke unless it's in raw mode
    On Friday, April 15, 2016 at 7:52:41 AM UTC-5, kay ru wrote:

    Your solution doesn't work. You have to type enter in the terminal.
    Test is here:

    http://play.golang.org/p/pnFctQa-Zl

    On Thursday, April 14, 2016 at 9:54:23 PM UTC+2, Skip wrote:

    perhaps you could use timeouts to abandon reads that take too long.
    here's a timed copy:

    https://gist.github.com/9nut/b874afee6a3cae629c9adc689d195884

    so long as there's keyboard input (terminated by newline) it will
    loop; otherwise it times out. closing stdin before timeout also works.
    On Thu, Apr 14, 2016 at 12:00 PM, kay ru wrote:

    Looks like it is possible to implement something like "readerCloser
    := ioutil.NopCloser(os.Stdin)" which could be closed. But even when call
    readerCloser.Close() it still doesn't work as expected and you have to type
    something in console manually.
    On Wednesday, April 13, 2016 at 7:03:32 PM UTC+2, Zippoxer wrote:

    Make your own Copy method that can be interrupted. Let me know if
    you want a snippet.
    On Wednesday, April 13, 2016 at 7:00:00 PM UTC+3, kay ru wrote:

    Hi,

    There are many use cases when you have to interrupt go func()
    {io.Copy(dst,src)}(). I've googled but still didn't find any solution on
    how to implement that.

    In my case I close writer: myWriter.Close() at the end of function,
    but io.Copy(myWriter,os.Stdin) still works. Don't know how to interrupt it.

    Thanks in advance.
    --
    You received this message because you are subscribed to the Google
    Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it,
    send an email to golang-nuts...@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Konstantin Khomoutov at Apr 15, 2016 at 2:09 pm

    On Fri, 15 Apr 2016 06:55:49 -0700 (PDT) kay ru wrote:

    Too hacky. There should be a way to interrupt Read. It is interrupted
    when you exit the process, so I hope there should be possibility to
    do that manually.
    There are two ways: close the FD or send a signal to the thread which
    is waiting in the syscall (and it has to have that signal unmasked and
    its disposition not set to SA_RESTART) so that the syscall is
    interrupted returning EINTR. Since Go has to fiddle with signal
    handling itself to make its runtime happy, I'd say you're left with the
    first option.

    Considering "interrupted when you exit the process" is in vain because
    when you exit the process the kernel cleans after for your process
    itself so it's free to do with the state of your process whatever it
    wants.

    [...]

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Kay ru at Apr 15, 2016 at 2:13 pm
    Closing of the FD doesn't allow you to use stdin in next iteration. Even if
    you'll try to open it again through: "newStdin :=
    os.NewFile(uintptr(syscall.Stdin), "/dev/stdin")"
    On Friday, April 15, 2016 at 4:10:11 PM UTC+2, Konstantin Khomoutov wrote:

    On Fri, 15 Apr 2016 06:55:49 -0700 (PDT)
    kay ru <kay....@gmail.com <javascript:>> wrote:
    Too hacky. There should be a way to interrupt Read. It is interrupted
    when you exit the process, so I hope there should be possibility to
    do that manually.
    There are two ways: close the FD or send a signal to the thread which
    is waiting in the syscall (and it has to have that signal unmasked and
    its disposition not set to SA_RESTART) so that the syscall is
    interrupted returning EINTR. Since Go has to fiddle with signal
    handling itself to make its runtime happy, I'd say you're left with the
    first option.

    Considering "interrupted when you exit the process" is in vain because
    when you exit the process the kernel cleans after for your process
    itself so it's free to do with the state of your process whatever it
    wants.

    [...]
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Lars Seipel at Apr 15, 2016 at 9:29 pm

    On Fri, Apr 15, 2016 at 07:13:49AM -0700, kay ru wrote:
    Closing of the FD doesn't allow you to use stdin in next iteration. Even if
    you'll try to open it again through: "newStdin :=
    os.NewFile(uintptr(syscall.Stdin), "/dev/stdin")"
    Actually, this doesn't open the file, but only creates an os.File
    structure for the (closed, or worse) file descriptor 0 (syscall.Stdin).

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Matt Harden at Apr 16, 2016 at 5:57 pm
    If you dup stdin and read from the dup'ed fd, you should be able to close
    that one and interrupt the read without closing stdin itself.
    On Fri, Apr 15, 2016 at 2:29 PM Lars Seipel wrote:
    On Fri, Apr 15, 2016 at 07:13:49AM -0700, kay ru wrote:
    Closing of the FD doesn't allow you to use stdin in next iteration. Even if
    you'll try to open it again through: "newStdin :=
    os.NewFile(uintptr(syscall.Stdin), "/dev/stdin")"
    Actually, this doesn't open the file, but only creates an os.File
    structure for the (closed, or worse) file descriptor 0 (syscall.Stdin).

    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Matt Harden at Apr 16, 2016 at 6:46 pm
    Apparently you can't interrupt the read syscall on a terminal by closing
    the fd if it's in line mode. The close returns but the read doesn't. I
    suspect even the select syscall wouldn't help here.
    On Sat, Apr 16, 2016 at 10:57 AM Matt Harden wrote:

    If you dup stdin and read from the dup'ed fd, you should be able to close
    that one and interrupt the read without closing stdin itself.
    On Fri, Apr 15, 2016 at 2:29 PM Lars Seipel wrote:
    On Fri, Apr 15, 2016 at 07:13:49AM -0700, kay ru wrote:
    Closing of the FD doesn't allow you to use stdin in next iteration. Even if
    you'll try to open it again through: "newStdin :=
    os.NewFile(uintptr(syscall.Stdin), "/dev/stdin")"
    Actually, this doesn't open the file, but only creates an os.File
    structure for the (closed, or worse) file descriptor 0 (syscall.Stdin).

    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Konstantin Khomoutov at Apr 15, 2016 at 2:01 pm

    On Fri, 15 Apr 2016 06:47:31 -0700 (PDT) C Banning wrote:

    Your program has to set the terminal in "raw" mode - "man stty"
    should help.
    See [1] for already existing pure-Go solution to do this.

    1. https://github.com/creack/termios

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Kay ru at Apr 19, 2016 at 5:32 pm
    Can you provide an example on how to avoid stdin buffering using this
    package?
    On Friday, April 15, 2016 at 4:02:09 PM UTC+2, Konstantin Khomoutov wrote:

    On Fri, 15 Apr 2016 06:47:31 -0700 (PDT)
    C Banning <clba...@gmail.com <javascript:>> wrote:
    Your program has to set the terminal in "raw" mode - "man stty"
    should help.
    See [1] for already existing pure-Go solution to do this.

    1. https://github.com/creack/termios
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Konstantin Khomoutov at Apr 19, 2016 at 5:48 pm

    On Tue, 19 Apr 2016 10:31:56 -0700 (PDT) kay ru wrote:

    Can you provide an example on how to avoid stdin buffering using this
    package?
    Combine [2] and [3] I suppose.

    2. https://github.com/creack/termios/blob/master/raw/raw_test.go#L58
    3. https://golang.org/pkg/os/#File.Fd

    [...]
    [...]

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Anton Khramov at Apr 14, 2016 at 6:00 pm
    Here is how I've tried to implement my own
    io.Copy: http://play.golang.org/p/fHxdtSnjsI

    But it doesn't work. It is blocked by "nr, er := teein.Read(buf)" and even
    sending fake data to the os.Stdin doesn't help.

    It is being unblocked only if you press any key in the terminal.
    On Wednesday, April 13, 2016 at 6:00:00 PM UTC+2, kay ru wrote:

    Hi,

    There are many use cases when you have to interrupt go func()
    {io.Copy(dst,src)}(). I've googled but still didn't find any solution on
    how to implement that.

    In my case I close writer: myWriter.Close() at the end of function,
    but io.Copy(myWriter,os.Stdin) still works. Don't know how to interrupt it.

    Thanks in advance.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Jarktasaa at Apr 15, 2016 at 5:10 pm
    You could wrap src with this: https://play.golang.org/p/Du9_jgwNuY and call
    the Cancel method on the returned struct to make future reads fail with
    io.EOF, which would stop an in progress copy
    On Wednesday, April 13, 2016 at 5:00:00 PM UTC+1, kay ru wrote:

    Hi,

    There are many use cases when you have to interrupt go func()
    {io.Copy(dst,src)}(). I've googled but still didn't find any solution on
    how to implement that.

    In my case I close writer: myWriter.Close() at the end of function,
    but io.Copy(myWriter,os.Stdin) still works. Don't know how to interrupt it.

    Thanks in advance.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Konstantin Khomoutov at Apr 15, 2016 at 5:30 pm

    On Fri, 15 Apr 2016 10:10:39 -0700 (PDT) jarktasaa@gmail.com wrote:

    You could wrap src with this: https://play.golang.org/p/Du9_jgwNuY
    and call the Cancel method on the returned struct to make future
    reads fail with io.EOF, which would stop an in progress copy
    Can you explain how it works?

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Alex Bligh at Apr 15, 2016 at 5:40 pm

    On 15 Apr 2016, at 18:10, jarktasaa@gmail.com wrote:

    You could wrap src with this: https://play.golang.org/p/Du9_jgwNuY and call the Cancel method on the returned struct to make future reads fail with io.EOF, which would stop an in progress copy
    How does that work?

    Firstly the 'default:' and 'case <-r.interupt:' appear to be inverted.

    Secondly, sending a cancel is not going to stop an inprogress (i.e. blocked) r.r.Read(p) as far as I can tell. It will merely skip subsequent reads.

    --
    Alex Bligh




    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedApr 13, '16 at 3:59p
activeApr 19, '16 at 5:48p
posts26
users11
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase