go-python / go-python/gopy

gen: support for channels

Đang mở
#67 3 bình luận 0 reaction 1 người được giao Được @sbinet nhận Xem trên GitHub
enhancement
Ngôn ngữ chính
Go
Star
2.3k
Fork
136
Merge trung bình
14 phút
Pull request đã merge (30 ngày)
2

Mô tả

Channel support is probably a ways off, but I guess it's good to make an explicit issue of it ;)

Building the package

```
package channel

func Channel() chan int {
return make(chan int)
}
```

fails when built with `go build channel.go && gopy gen`. The following message is generated:

```
panic: unhandled obj [*types.Var]
type [&types.Chan{dir:0, elem:(*types.Basic)(0x53fac0)}]

goroutine 1 [running]:
github.com/go-python/gopy/bind.(*symtab).addType(0x8205d33c0, 0x8820778b78, 0x820623db0, 0x8820778b18, 0x8205d2fc0)
/Users/phil/code/go/src/github.com/go-python/gopy/bind/symtab.go:447 +0x522
github.com/go-python/gopy/bind.(*symtab).processTuple(0x8205d33c0, 0x8205d2fe0)
/Users/phil/code/go/src/github.com/go-python/gopy/bind/symtab.go:349 +0x149
github.com/go-python/gopy/bind.(*symtab).addSymbol(0x8205d33c0, 0x8820778408, 0x820623d10)
/Users/phil/code/go/src/github.com/go-python/gopy/bind/symtab.go:330 +0xd0a
github.com/go-python/gopy/bind.(*Package).process(0x82064af00, 0x0, 0x0)
/Users/phil/code/go/src/github.com/go-python/gopy/bind/package.go:179 +0x26dd
github.com/go-python/gopy/bind.NewPackage(0x820623c70, 0x820663880, 0x16, 0x0, 0x0)
/Users/phil/code/go/src/github.com/go-python/gopy/bind/package.go:44 +0x390
main.newPackageFrom(0x8205ea0a0, 0x1, 0x1, 0x82064adc0, 0x820664000, 0x8205ea0a0, 0x0, 0x0)
/Users/phil/code/go/src/github.com/go-python/gopy/gen.go:209 +0x3bf
main.newPackage(0x7fff5fbffa41, 0x1, 0x8205d0104, 0x0, 0x0)
/Users/phil/code/go/src/github.com/go-python/gopy/gen.go:179 +0x638
main.gopyRunCmdGen(0x820634a20, 0x8205cc260, 0x1, 0x1, 0x0, 0x0)
/Users/phil/code/go/src/github.com/go-python/gopy/cmd_gen.go:75 +0x588
github.com/gonuts/commander.(*Command).Dispatch(0x820634a20, 0x8205cc260, 0x1, 0x1, 0x0, 0x0)
/Users/phil/code/go/src/github.com/gonuts/commander/commands.go:221 +0x7e2
github.com/gonuts/commander.(*Command).Dispatch(0x820634c60, 0x8205cc250, 0x2, 0x2, 0x0, 0x0)
/Users/phil/code/go/src/github.com/gonuts/commander/commands.go:187 +0x1f9
main.main()
/Users/phil/code/go/src/github.com/go-python/gopy/main.go:42 +0x1fe
```

One potential way to handle this would be to equate channels and [multiprocessing.Connection](https://docs.python.org/2/library/multiprocessing.html#multiprocessing.Connection) objects. When a channel is returned by a Go function, gopy calls [multiprocessing.Pipe](https://docs.python.org/2/library/multiprocessing.html#multiprocessing.Pipe), and passes one `Connection` to a new listening thread and returns the other to the calling process. When the listening thread receives a value through its `Connection`, it calls a Go function that passes the value to the equivalent underlying channel.

The same strategy could be used in the other direction for passing a channel/`Connection` to a Go function from Python.

It might also make sense to create some class `class ChanConnection(multiprocessing.Connection)` which stores an explicit reference to the underlying channel, so that in the case where a Python routine passes a channel created in Go back to another Go routine, values passed through it don't need to pass back and forth through Python.

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.