On Tue, Sep 5, 2017 at 10:03 PM, Jason Wang <silentr...@gmail.com> wrote: > > I have the following two files: > > // hello.go > package main > > import ( > "fmt" > ) > > func Hello() { > fmt.Println("hello") > } > > func main() {} > > > build as plugin: `go build -buildmode=plugin hello.go` > > // main.go > package main > > import ( > "log" > "plugin" > "time" > ) > > func main() { > for { > log.Println("start load plugin.") > time.Sleep(time.Second) > p, err := plugin.Open("../hello.so") > if err != nil { > log.Println(err) > continue > } > > sym, err := p.Lookup("Hello") > if err != nil { > log.Println(err) > continue > } > > hello, ok := sym.(func()) > if !ok { > log.Println(err) > continue > } > > for i := 0; i < 10; i++ { > hello() > time.Sleep(time.Second) > } > } > } > > // `go build main.go` > > > main.go keeps calling the Hello function from hello.so file. I tried to > modify the hello.go file, and re-built the hello.so file. The so file was > successfully replaced. However, the main process was still printing the old > world "hello". It seems the so file in memory was not changed, even the main > program reloaded the so file once for a while. > Restarting the main process could make it work. But it is not what i am > looking for. > > How could I dynamically update the so file and make it applied in main > process?
I don't think there is any way to do this at present. The closest you can come is to use a new name for plugin.Open. Doing so may help make more clear that there is no plugin.Close, so every time you open a new plugin you are taking up a bit more of the program's address space. Ian -- 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.