Re: [go-nuts] cgo and time.After
Dear Jakob and all, indeed I was blind. This works like a charm: amount := 42 remaining := amount ticker := time.NewTicker(5 * time.Second) defer ticker.Stop() for remaining > 0 { select { case <-ticker.C: fmt.Printf("Progress: %d left from %d\n", remaining, amount) case <-donChan: remaining-- case res := <-resChan: fmt.Println(res) } } thanks all! Chris On Saturday, May 19, 2018 at 9:16:19 PM UTC+2, Jakob Borg wrote: > > On 19 May 2018, at 16:25, Chris Burkert > > wrote: > > > > case <-time.After(5 * time.Second): > > fmt.Printf("Progress: %d left from %d\n", remaining, amount) > > It's not super clear from your post if you're aware of this already, but > this case will only fire after the select has been blocked for five > seconds. If there is any activity on the other cases one of those will > proceed, you'll get another loop iteration, and another five second timeout > before status output. > > Typically you'd use a five second ticker instead to get a channel event > every five seconds and use that to print status output. > > //jb -- 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. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] cgo and time.After
Jakob, I think you’re right. I am going to test this as soon as I am back home. After all I am a beginner in this area and it seems this one fooled me. I’ll send an update tomorrow. thanks - Chris Jakob Borg schrieb am Sa. 19. Mai 2018 um 21:15: > On 19 May 2018, at 16:25, Chris Burkert wrote: > > > > case <-time.After(5 * time.Second): > > fmt.Printf("Progress: %d left from %d\n", remaining, amount) > > It's not super clear from your post if you're aware of this already, but > this case will only fire after the select has been blocked for five > seconds. If there is any activity on the other cases one of those will > proceed, you'll get another loop iteration, and another five second timeout > before status output. > > Typically you'd use a five second ticker instead to get a channel event > every five seconds and use that to print status output. > > //jb -- 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. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] cgo and time.After
On 19 May 2018, at 16:25, Chris Burkert wrote: > > case <-time.After(5 * time.Second): > fmt.Printf("Progress: %d left from %d\n", remaining, amount) It's not super clear from your post if you're aware of this already, but this case will only fire after the select has been blocked for five seconds. If there is any activity on the other cases one of those will proceed, you'll get another loop iteration, and another five second timeout before status output. Typically you'd use a five second ticker instead to get a channel event every five seconds and use that to print status output. //jb -- 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. For more options, visit https://groups.google.com/d/optout.
[go-nuts] cgo and time.After
Show the code! This should not be cgo error, but user error! -- 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. For more options, visit https://groups.google.com/d/optout.
[go-nuts] cgo and time.After
Dear Gophers, I am working on a small database tool which checks a database for inconsistencies. It does that by calling a stored procedure via sql. Unfortunately the database client is available as C-library only but luckily there is a go driver for the database/sql package so at least it feels like pure go. Of course it is not as it uses cgo under the hood. After all I got the basics working based on the following: 1. a producer goroutine reads from the database, creates the sql statements to be run and passes them into a task channel 2. eight worker goroutines read from the task channel, run one task at a time on the database and pass the result to a results channel (resChan) 3. main reads the results from the results channel So far, so good. Then I wanted to add some progress info. As I know the number of checks I added another channel (donChan). Each worker goroutine sends an empty struct on that channel after a check has been finished. main reads from that channel and decreases the remaining number of checks. In the end I have something like this: amount := 42 remaining := amount for remaining > 0 { select { case <-time.After(5 * time.Second): fmt.Printf("Progress: %d left from %d\n", remaining, amount) case <-donChan: remaining-- case res := <-resChan: fmt.Println(res) } } This is simplified but I hope you get the idea. The effect is that as long as the eight worker and the producer goroutines are running and using the database, I don't see the progress message which should be triggered by time.After. To me it looks like the runtime is busy with the large cgo threads and cannot handle/schedule the time.After goroutine. But when I raise variable amount for testing while the number of actual checks is lower (then the for look will run forever) I see the Progress output as soon as the worker and the producer goroutines are done. So the time.After is not dead - it's just blocked while cgo is used. And here I would like to ask you for tips and help. If you have an idea and you need more details please let me know. I also came across Dave Cheneys post https://dave.cheney.net/2016/01/18/cgo-is-not-go and I believe this is what I am suffering from. Unfortunately there is no other database client available. It is about SAPs database HANA and I know there is a pure go implementation. Unfortunately this one lacks hdbuserstore support which is some kind of password store for HANA I need. So I have to use the official HANA client based on the C-library. thanks for any help! Chris PS: I am using go 1.10.2 and also tried 1.10 with the same result -- 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. For more options, visit https://groups.google.com/d/optout.