gopherdata / gophernotes

The Go kernel for Jupyter notebooks and nteract.
MIT License
3.82k stars 265 forks source link

Got internal error when running a 'select' code block #155

Closed hyiyang closed 5 years ago

hyiyang commented 5 years ago

I was trying the 'select' feature in Golang and found an error while executing SelectTest() in my Jupyter Notebook. Not sure if this is a bug, however SelectTest() is OK in my VS Code.

Detail as follows: Jupyter Notebook output:

repl.go:31:39: internal error: containLocalBinds() returned false, but block actually defined 1 Binds and 0 IntBinds:
    Binds = map[]
    Block =
{

    select {
    case x := <-c1:
        go func() {
            fmt.Println("Got", x, "from c1")
        }()

    case x := <-c2:
        go func() {
            fmt.Println("Got", x, "from c2")
        }()
    }
}

My Code:

//block 1
import (
    "fmt"
    "math/rand"
    "time"
)

//block 2
func SelectTest() {
    c1 := make(chan int)
    c2 := make(chan int)

    randomSource := rand.NewSource(time.Now().UnixNano())
    randomGenerator := rand.New(randomSource)

    go func() {
        for {
            time.Sleep(5 * time.Second)
            c1 <- randomGenerator.Intn(100)
        }
    }()

    go func() {
        for {
            time.Sleep(8 * time.Second)
            c2 <- randomGenerator.Intn(100)
        }
    }()

    for {
        select {
        case x := <-c1:
            go func() {
                fmt.Println("Got", x, "from c1")
            }()

        case x := <-c2:
            go func() {
                fmt.Println("Got", x, "from c2")
            }()
        }
    }
}

SelectTest()
cosmos72 commented 5 years ago

Hello, it looks very similar to upstream bug https://github.com/cosmos72/gomacro/issues/46 which should be fixed in commit d531e1ad659140a02ba3d5d2324081185c4a85ea.

Can you try again after updating gophernotes?

hyiyang commented 5 years ago

@cosmos72 Thank you. I can confirm the issue is gone after updating gophernotes.