[go-nuts] Re: Problems refactoring call to Open()

2017-06-21 Thread Michael Dwyer
Peter, with your responses I was able to figure out the cause of the error. I created a function that calls defer. I did it as a function as I put some trace code in along with the Close(). >From that I concluded you were correct. I went ahead and reworked the rest of the code, which was my

[go-nuts] Re: Problems refactoring call to Open()

2017-06-21 Thread Michael Dwyer
Peter, Thank you for helping me out. I'm going to be busy the next couple of days. When I have some free time I will go over your replies. Seems that my analysis was inadequate. I do appreciate the points you made. Gives me an opportunity to try some different code tweaks. When I am able I

[go-nuts] max connections limit lib/pq

2017-06-21 Thread Tamás Gulácsi
You have to carefully close every Rows, Stmt, Tx and Conn acquired by database/sql. -- 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

[go-nuts] Re: Go's scheduler always “stuck” after certain time when executing the code below

2017-06-21 Thread 'David Chase' via golang-nuts
Try compiling your code with -gcflags -d=ssa/insert_resched_checks/on . You should see the scheduler thrashing stop, at the expense of some loop overhead. (The simpler the loop, the worse the overhead, that is why this phase is not normally enabled. We're working on the overhead issues, they've

[go-nuts] Re: Go's scheduler always “stuck” after certain time when executing the code below

2017-06-21 Thread Chris Hines
See also: https://github.com/golang/go/issues/10958 On Wednesday, June 21, 2017 at 1:12:12 AM UTC-4, Ronald wrote: > > I found this: https://github.com/golang/go/issues/7190. > > Then I replace : > > go func() { > for { > } > }() > > With: > > > go func() { > ct := 0 >

[go-nuts] Re: Problems refactoring call to Open()

2017-06-21 Thread peterGo
Michael, func openFile(s string, file *os.File) { file, err := os.Open(s) if err != nil { log.Fatal(err) } defer file.Close() } There are two errors. When openfile returns file is closed and it is no longer valid. In Go, all arguments are passed by value, When openFile

[go-nuts] Re: Problems refactoring call to Open()

2017-06-21 Thread peterGo
Michael, In Go, all arguments are passed by value. Therefore the value of file is discarded at the end of openfile. In main, f remains nil. Peter On Wednesday, June 21, 2017 at 4:58:58 PM UTC, Michael Dwyer wrote: > > Peter, > > Thank you for your input regarding my question. > > In an effort

[go-nuts] Re: Problems refactoring call to Open()

2017-06-21 Thread peterGo
Michael, Your first post was clear. Therefore the error remains. When you close the file you lose the fd. f is nil. For example, package main import ( "bufio" "flag" "fmt" "log" "os" ) func cli() string { flag.Parse() return flag.Arg(0) } func openFile(s string,

[go-nuts] Re: Handling errors in functions

2017-06-21 Thread 'Eric Johnson' via golang-nuts
My take is something like the following would be more idiomatic // SummonerByName returns profile address and an error. We need it in case where // we cannot get the profile for some reason func SummonerByName(name string, server string) (*SummonerProfile, error) { var resp, err =

Re: [go-nuts] Go 1.9 Beta 1 is released

2017-06-21 Thread Sam Whited
This made me smile; I hadn't seen that. Wish I had been there to see the audiences faces (or had headphones to find out if they're in the video) :) —Sam On Thu, Jun 15, 2017 at 10:56 AM, Brad Fitzpatrick wrote: > > > On Thu, Jun 15, 2017 at 8:54 AM, Michael Banzon

[go-nuts] Re: How to include unused functions into binary

2017-06-21 Thread prades . marq
Nowhere in the piece of code you pasted you are calling a function, you are trying to call a struct method on the other hand ( method.Call ). Your error comes from something else and not the fact Go removes unused functions. Furthermore, if the number of possible struct methods to call is

[go-nuts] Re: Problems refactoring call to Open()

2017-06-21 Thread Michael Dwyer
Peter, Thank you for your input regarding my question. In an effort to clear up any confusion or ambiguity regarding the problem I am running into, I will post the code for what is working and the code that is not working. The following block of code works, a valid file is passed to the

[go-nuts] Re: Handling errors in functions

2017-06-21 Thread suburb4nfilth
Thank you both for the suggestions. -- 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

Re: [go-nuts] Handling errors in functions

2017-06-21 Thread Marvin Renich
* Marvin Renich [170621 09:48]: > package main > > import ( > "fmt" > ) > > func Calc(a int) (r int, err error) { > if a == 0 { > err = fmt.Errorf("Bad argument") > return > } > r = 72 / a > return > } > > func main() {

Re: [go-nuts] Go's scheduler always “stuck” after certain time when executing the code below

2017-06-21 Thread Sen Han
> just add a function call occasionally depending on your required latency bound Thanks Jesper for your all detailed explanation. I quite agree with your point of view and conclusion. One thing left here should to be discussed is about the go scheduler's unwanted behaviour. Unwanted behaviour

[go-nuts] Re: How to include unused functions into binary

2017-06-21 Thread John Kenedy
Below is some part of the code func (*ScrapperMin) ExecuteFunction(funcname string, obj interface{}, args [][]string) (interface{}, error) { inputs := make([]reflect.Value, 0) inputs2 := make([]string, 0) //var single = true var tt = make([]reflect.Value, 0) for i, _ := range args { if

Re: [go-nuts] Handling errors in functions

2017-06-21 Thread Marvin Renich
* suburb4nfi...@gmail.com [170621 08:44]: > Is it possible to give a default nil value to an error at the beginning of > a function and then just assign to it in case of need ? What I want to do > is something like the following : > > func GetSummonerByName(name

Re: [go-nuts] Go's scheduler always “stuck” after certain time when executing the code below

2017-06-21 Thread Jesper Louis Andersen
On Wed, Jun 21, 2017 at 5:40 AM Ronald wrote: > Hi, I found when running this code below (play > ): > > > You are looking at a property of a specific Go implementation, not a property of the language. Any system must define a set of

Re: [go-nuts] Re: Go's scheduler always “stuck” after certain time when executing the code below

2017-06-21 Thread Ronald
It seems really pointless if you've got lots of work to do to have to sit > in a delay. > Some CPU intensive application indeed sit here and do some massive mathematic calculation and memory manipulation.There is too many examples, say some de/en-coding worker for example. > Would not a

[go-nuts] Re: Problems refactoring call to Open()

2017-06-21 Thread peterGo
Michael, func openFile(s string, file *os.File) { file, err := os.Open(s) if err != nil { log.Fatal(err) } defer file.Close() } You open the file and when the function exits, close the file. Peter On Wednesday, June 21, 2017 at 12:44:36 PM UTC, Michael Dwyer wrote: > > Hello to all, > > My

Re: [go-nuts] Re: Go's scheduler always “stuck” after certain time when executing the code below

2017-06-21 Thread Chris Hopkins
> > > Particularly, delays should be implemented using the functions in the time > > package, not by burning CPU cycles at the expense of other useful work > > that could have been done instead. > > > Sure this kinda of dead loop is just an simulation about some really CPU > intensive jobs. >

Re: [go-nuts] Re: Go's scheduler always “stuck” after certain time when executing the code below

2017-06-21 Thread Ronald
And I had write a test case to be a proof that: *current golang's scheduler is not* *good at cpu intensive applications* Here it is: package main import "fmt" import "runtime" //import "math/big" import "time" /* #include #include #include #include #include int deadloop() { long

Re: [go-nuts] How to include unused functions into binary

2017-06-21 Thread Jan Mercl
On Wed, Jun 21, 2017 at 2:44 PM wrote: > I read somewhere that Go will remove unused functions so that it wont be included into binaries when it can prove no code is using it. Correct. > However I am using reflection to call functions that are inside the binaries

[go-nuts] max connections limit lib/pq

2017-06-21 Thread Tieson Molly
I am running into an issue I have seen mentioned on here years ago. I am seeking the current best solution. I have a web server connecting to a postgresql database using the standard database/sql and the lib/pq driver. I keep running out of connections over time as it seems the pool grows up

Re: [go-nuts] Re: Go's scheduler always “stuck” after certain time when executing the code below

2017-06-21 Thread Sen Han
> > This piece of code prohibits cooperative scheduling in 599 999 999 out of 600 000 000 times. It's a nice example how to not code in Go. Thanks Jan for your reply :) > Particularly, delays should be implemented using the functions in the time package, not by burning CPU cycles at the

[go-nuts] Problems refactoring call to Open()

2017-06-21 Thread Michael Dwyer
Hello to all, My first time posting questions here, so please bear with me, I'm willing to learn. I have a simple piece of code, which opens a file, reads the contents and counts the number of lines in the file. What I am attempting to do is to refactor the code. The error occurs when I read

[go-nuts] Handling errors in functions

2017-06-21 Thread suburb4nfilth
Hey, Is it possible to give a default nil value to an error at the beginning of a function and then just assign to it in case of need ? What I want to do is something like the following : func GetSummonerByName(name string, server string) *SummonerProfile err { //The function should return

[go-nuts] How to include unused functions into binary

2017-06-21 Thread sorainnosia
I read somewhere that Go will remove unused functions so that it wont be included into binaries when it can prove no code is using it. However I am using reflection to call functions that are inside the binaries without first having any variable using it. Is there compiler option to include

Re: [go-nuts] Re: Go's scheduler always “stuck” after certain time when executing the code below

2017-06-21 Thread Jan Mercl
On Wed, Jun 21, 2017 at 1:50 PM Ronald wrote: > for { > ct++ > if ct%6 == 0 { > t2 := time.Now().UnixNano() > fmt.Println("hooray", t2, t1, float64(t2-t1)/1e6) > t1 = t2 > } > } > This piece

[go-nuts] Re: Go's scheduler always “stuck” after certain time when executing the code below

2017-06-21 Thread Ronald
> > > Replace : > go func() { for { > } > }() > With: > > go func() { > ct := 0 > t1 := time.Now().UnixNano() > for { > ct++ > if ct%6 == 0 { > t2 := time.Now().UnixNano() >

[go-nuts] Re: Go's scheduler always “stuck” after certain time when executing the code below

2017-06-21 Thread Ronald
On Wednesday, 21 June 2017 12:55:23 UTC+8, Dave Cheney wrote: > > Yes, this is expected. Don't write infinite loops like that. Sorry Dave, but I still couldn't get why it would 'stuck' for the very first piece of code. Of course it would be pretty reasonable that the go process would be

[go-nuts] Re: Go's scheduler always “stuck” after certain time when executing the code below

2017-06-21 Thread Dave Cheney
Go is not good for functions which never call other, take locks, read or write data, or communicate with others. In practice, most code does one or more of these things so it's rarely an issue. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group.