Re: [go-nuts] How to kill running function from core golang libraries
Thank you all for your response Jake - thank you for clarification and yes you are correct. Application works like checksum validation server,client. Terminate is only useful if user triggered server to download a very large file but figured wrong setting present and i.e. does ctrl+c on client yet still it is matter of seconds. For the exact same reason I have postponed but I wanted to investigate if there is a way. I will give a shot this weekend for the io.Reader Burak On Friday, November 1, 2019 at 4:54:00 PM UTC+1, Jake Montgomery wrote: > > On Friday, November 1, 2019 at 10:30:50 AM UTC-4, Shulhan wrote: >> >> >> On Fri, 1 Nov 2019, 21:07 burak sarac, wrote: >> >>> I have a go routine running something like 'hash.sum(data)' using import >>> "hash" that I want to terminate immediately in case of user wants to >>> kill, I can not send channel to notify. >>> >> >> >> I have not tried this, but you can use a combination of defer, panic and >> recover to unroll the process. >> >> The recover function is inside calculate, and the for-loop is running in >> goroutine before calculate. >> >>defer func() { recover() } >>go loop() >>calculate() >> >> Inside the loop() you will call panic("terminate"). >> >> -- Shulhan >> > > Shulhan - I think the point was that Burak does not have control over the > code for the function that we want to interrupt. So he has no ability to > insert a panic. > > Burak - I do not believe there is a generic way to interrupt a function or > goroutine which does not take a Context, or have some other interruption > method baked in. I know the idea of being able to "kill" a goroutine has > been discussed before, and has generally gone nowhere. > > It might be useful to have more details of the call, and to understand why > you need to interrupt this function. Assuming the hash.sum() you refer to > takes a []byte, then how long could it reasonably take? The best bet might > be to simply let it finish and ignore the result. Of course, if the > function is being sourced off an io.Reader(), or something like that, then > you might be able to interrupt the stream by wrapping the interface with > some of your own code. > > -- 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...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/6e941dc9-2cca-4050-ae6b-1a3066337a8a%40googlegroups.com.
Re: [go-nuts] How to kill running function from core golang libraries
On Fri, Nov 1, 2019 at 8:07 AM burak sarac wrote: > > I have a go routine running something like 'hash.sum(data)' using import > "hash" that I want to terminate immediately in case of user wants to kill, I > can not send channel to notify. I only can think of copying implementation > but then I have to watch each update on library which I really dont want to > mess with. Do you have any suggestions? Code is here > > https://github.com/getsumio/getsum/blob/master/internal/supplier/gosupplier.go#L115 Can you provide a customized hash implementation that will panic based on a flag? > > Thank you too much for help:) > Burak > > -- > 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...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/716c9b47-e84b-4aea-b061-45604fd1561e%40googlegroups.com. -- 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...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAMV2RqpZ3OnA4rtvYHvuE5Juuof1HT4hv%2B4weOnk%2B%2BvcYAHd9g%40mail.gmail.com.
Re: [go-nuts] How to kill running function from core golang libraries
On Friday, November 1, 2019 at 10:30:50 AM UTC-4, Shulhan wrote: > > > On Fri, 1 Nov 2019, 21:07 burak sarac, > > wrote: > >> I have a go routine running something like 'hash.sum(data)' using import >> "hash" that I want to terminate immediately in case of user wants to >> kill, I can not send channel to notify. >> > > > I have not tried this, but you can use a combination of defer, panic and > recover to unroll the process. > > The recover function is inside calculate, and the for-loop is running in > goroutine before calculate. > >defer func() { recover() } >go loop() >calculate() > > Inside the loop() you will call panic("terminate"). > > -- Shulhan > Shulhan - I think the point was that Burak does not have control over the code for the function that we want to interrupt. So he has no ability to insert a panic. Burak - I do not believe there is a generic way to interrupt a function or goroutine which does not take a Context, or have some other interruption method baked in. I know the idea of being able to "kill" a goroutine has been discussed before, and has generally gone nowhere. It might be useful to have more details of the call, and to understand why you need to interrupt this function. Assuming the hash.sum() you refer to takes a []byte, then how long could it reasonably take? The best bet might be to simply let it finish and ignore the result. Of course, if the function is being sourced off an io.Reader(), or something like that, then you might be able to interrupt the stream by wrapping the interface with some of your own code. -- 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...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/e9464b1d-f753-4df4-9d29-e6d19cf870d2%40googlegroups.com.
Re: [go-nuts] How to kill running function from core golang libraries
On Fri, 1 Nov 2019, 21:07 burak sarac, wrote: > I have a go routine running something like 'hash.sum(data)' using import > "hash" that I want to terminate immediately in case of user wants to > kill, I can not send channel to notify. > I have not tried this, but you can use a combination of defer, panic and recover to unroll the process. The recover function is inside calculate, and the for-loop is running in goroutine before calculate. defer func() { recover() } go loop() calculate() Inside the loop() you will call panic("terminate"). -- Shulhan > -- 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...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAMh9%2BYA%3DYW9gp6gtduRMyh_Zu567CJ97r8PcR-Wzp9HEz2%2BxHg%40mail.gmail.com.
[go-nuts] How to kill running function from core golang libraries
I have a go routine running something like 'hash.sum(data)' using import " hash" that I want to terminate immediately in case of user wants to kill, I can not send channel to notify. I only can think of copying implementation but then I have to watch each update on library which I really dont want to mess with. Do you have any suggestions? Code is here https://github.com/getsumio/getsum/blob/master/internal/supplier/gosupplier.go#L115 Thank you too much for help:) Burak -- 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...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/716c9b47-e84b-4aea-b061-45604fd1561e%40googlegroups.com.