go-python / go-python/gopy

gen: support for channels

Ouverte
#67 3 commentaires 0 réactions 1 personne assignée Réclamée par @sbinet Voir sur GitHub
enhancement
Langage dominant
Go
Étoiles
2.3k
Forks
136
Merge moyen
14 min
PR mergées (30 j)
2

Description

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.

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.