Re: [go-nuts] Context cancellation: Is it sufficient to make long-running things interruptible?

2022-12-19 Thread Harris, Andrew
. From: golang-nuts@googlegroups.com on behalf of Torsten Bronger Sent: Monday, December 19, 2022 1:52:36 AM To: golang-nuts@googlegroups.com Subject: [go-nuts] Context cancellation: Is it sufficient to make long-running things interruptible? Hallöchen! The context

Re: [go-nuts] Context cancellation: Is it sufficient to make long-running things interruptible?

2022-12-19 Thread Jan Mercl
On Mon, Dec 19, 2022 at 11:01 AM Torsten Bronger wrote: > The context documentation gives this example: > > // Stream generates values with DoSomething and sends them to out > // until DoSomething returns an error or ctx.Done is closed. > func Stream(ctx context.Context, out chan<- Va

[go-nuts] Context cancellation: Is it sufficient to make long-running things interruptible?

2022-12-19 Thread Torsten Bronger
Hallöchen! The context documentation gives this example: // Stream generates values with DoSomething and sends them to out // until DoSomething returns an error or ctx.Done is closed. func Stream(ctx context.Context, out chan<- Value) error { for { v, err := Do

[go-nuts] context cancellation in exec.CommandContext and os.Exit

2020-01-19 Thread Tamás Gulácsi
Yes. Never call os.Exit when you still has work to be done. Even defers are skipped. -- 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+unsubscr...@goog

[go-nuts] context cancellation in exec.CommandContext and os.Exit

2020-01-19 Thread Manlio Perillo
Hi. Suppose I have a program that spawns a process with exec.CommandContex and, in a signal handler, cancel the context and calls os.Exit(1). Is it possible, in theory, that the program exits before the process is actually terminated? Thanks Manlio Perillo -- You received this message becau

[go-nuts] context cancellation flake

2017-09-15 Thread Tamás Gulácsi
You "readBody" after "defer cancel()", so response length amd caching may provide you a body, maybe just a canceled context. -- 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 a

[go-nuts] context cancellation flake

2017-09-15 Thread kynrai
Hello, I was wondering if anyone could help me with understanding the behaviour of cancelling context on a request before its read. I am using golang 1.9 on macOS X sierra (latest) Sometimes this code returns context cancelled, sometimes it works. package main import ( "context" "io/i

Re: [go-nuts] Context cancellation

2016-11-03 Thread Gustavo Niemeyer
Glad it's being useful, and indeed, that API looks familiar. Nice. On Nov 3, 2016 4:33 PM, "Chris Hines" wrote: > FWIW, I'm a big fan of gopkg.in/tomb.v2. For similar functionality using > contexts consider golang.org/x/sync/errgroup. > > On Wednesday, November 2, 2016 at 7:55:59 PM UTC-4, Gusta

Re: [go-nuts] Context cancellation

2016-11-03 Thread Chris Hines
FWIW, I'm a big fan of gopkg.in/tomb.v2. For similar functionality using contexts consider golang.org/x/sync/errgroup. On Wednesday, November 2, 2016 at 7:55:59 PM UTC-4, Gustavo Niemeyer wrote: > > You said the function would return whether it got cancelled or not, so I > assumed something like

Re: [go-nuts] Context cancellation

2016-11-02 Thread Gustavo Niemeyer
You said the function would return whether it got cancelled or not, so I assumed something like err := foo.CallAPI(ctx), which would be awkward to return without actually canceling. Yes, if the function is documented to return with background activity, it's of course fine. That said, It's extremel

Re: [go-nuts] Context cancellation

2016-11-02 Thread 'Axel Wagner' via golang-nuts
In a concurrent world, assuming that a call to cancel means that thing actually got cancelled is dubious at best. For example, you could call cancelFunc, then immediately enter a GC pause, the other goroutine finishes their work in a orderly fashion, you unpause and close the underlying channel. Ve

Re: [go-nuts] Context cancellation

2016-11-02 Thread Gustavo Niemeyer
On Thu, Nov 3, 2016 at 1:27 AM, Axel Wagner wrote: > That is actually a great point I haven't thought about and the crux of the > matter (sorry for repeating it, but I think it's worth making very > explicit): > > While cancelFunc can only be called from the goroutine that created the > context,

Re: [go-nuts] Context cancellation

2016-11-02 Thread 'Axel Wagner' via golang-nuts
That is actually a great point I haven't thought about and the crux of the matter (sorry for repeating it, but I think it's worth making very explicit): While cancelFunc can only be called from the goroutine that created the context, Err can be called downstack. Meaning, if I call cancelFunc, a ca

Re: [go-nuts] Context cancellation

2016-11-02 Thread Gustavo Niemeyer
On Wed, Nov 2, 2016 at 9:11 PM, Ian Davis wrote: > On Wed, Nov 2, 2016, at 10:35 PM, Gustavo Niemeyer wrote: > > Hello there, > > On Wed, Nov 2, 2016 at 11:09 AM, Ian Davis wrote: > > > > On Wed, Nov 2, 2016, at 12:56 PM, 'Axel Wagner' via golang-nuts wrote: > > AIUI: A child or grandchild funct

Re: [go-nuts] Context cancellation

2016-11-02 Thread Ian Davis
On Wed, Nov 2, 2016, at 10:35 PM, Gustavo Niemeyer wrote: > Hello there, > > On Wed, Nov 2, 2016 at 11:09 AM, Ian Davis wrote: >> __ >> >> On Wed, Nov 2, 2016, at 12:56 PM, 'Axel Wagner' via golang- >> nuts wrote: >>> AIUI: A child or grandchild function is not supposed to signal that. >>> They ca

Re: [go-nuts] Context cancellation

2016-11-02 Thread Gustavo Niemeyer
Hello there, On Wed, Nov 2, 2016 at 11:09 AM, Ian Davis wrote: > On Wed, Nov 2, 2016, at 12:56 PM, 'Axel Wagner' via golang-nuts wrote: > > AIUI: A child or grandchild function is not supposed to signal that. They > can return an error and let the parent cancel, or they can create their own > ch

Re: [go-nuts] Context cancellation

2016-11-02 Thread Ian Davis
On Wed, Nov 2, 2016, at 12:56 PM, 'Axel Wagner' via golang-nuts wrote: > AIUI: A child or grandchild function is not supposed to signal that. > They can return an error and let the parent cancel, or they can create > their own child context WithCancel and cancel that. Context doesn't > replace exce

Re: [go-nuts] Context cancellation

2016-11-02 Thread 'Axel Wagner' via golang-nuts
AIUI: A child or grandchild function is not supposed to signal that. They can return an error and let the parent cancel, or they can create their own child context WithCancel and cancel that. Context doesn't replace exceptions. You should consider context a way to implement dynamic scoping

Re: [go-nuts] Context cancellation

2016-11-02 Thread Ian Davis
On Wed, Nov 2, 2016, at 12:12 PM, Axel Wagner wrote: > From https://godoc.org/context > >> Failing to call the CancelFunc leaks the child and its children until >> the parent is canceled or the timer fires. The go vet tool checks >> that CancelFuncs are used on all control-flow paths. > > I'm not s

Re: [go-nuts] Context cancellation

2016-11-02 Thread 'Axel Wagner' via golang-nuts
>From https://godoc.org/context Failing to call the CancelFunc leaks the child and its children until the > parent is canceled or the timer fires. The go vet tool checks that > CancelFuncs are used on all control-flow paths. I'm not sure how it's *meant* to be used, but a way to do it, while adh

[go-nuts] Context cancellation

2016-11-02 Thread Ian Davis
Hi all, I'm trying to understand the idioms around cancellation of contexts. I've read the godoc and the relevant blog (https://blog.golang.org/context). Should you always call the cancelFunc of a cancellable context? Or should it only be called if the operation is terminated before successful co