Comments (7)
(took the liberty to reformat slightly your submission)
from go-python.
I haven't checked my hypothesis yet but I surmise this is because you haven't checked whether an exception was raised (possibly with PyErr_Occurred
[1]) and then cleared it (with PyErr_Clear
[2])
[1] https://godoc.org/github.com/sbinet/go-python#PyErr_Occurred
[2] https://godoc.org/github.com/sbinet/go-python#PyErr_Clear
from go-python.
Yes. Its not checked for exception in our code.
Will try this and update. Thanks for the quick response.
Regards
Shubhendu
On 13 Jan 2016 02:03, "Sebastien Binet" [email protected] wrote:
I haven't checked my hypothesis yet but I surmise this is because you
haven't checked whether an exception was raised (possibly with
PyErr_Occurred [1]) and then cleared it (with PyErr_Clear [2])[1] https://godoc.org/github.com/sbinet/go-python#PyErr_Occurred
[2] https://godoc.org/github.com/sbinet/go-python#PyErr_Clear—
Reply to this email directly or view it on GitHub
#33 (comment).
from go-python.
Thanks the solution works fine. ...
On 13 Jan 2016 10:36, "Shubhendu Tripathi" [email protected]
wrote:
Yes. Its not checked for exception in our code.
Will try this and update. Thanks for the quick response.Regards
Shubhendu
On 13 Jan 2016 02:03, "Sebastien Binet" [email protected] wrote:I haven't checked my hypothesis yet but I surmise this is because you
haven't checked whether an exception was raised (possibly with
PyErr_Occurred [1]) and then cleared it (with PyErr_Clear [2])[1] https://godoc.org/github.com/sbinet/go-python#PyErr_Occurred
[2] https://godoc.org/github.com/sbinet/go-python#PyErr_Clear—
Reply to this email directly or view it on GitHub
#33 (comment).
from go-python.
Hi Sebastien,
Thanks for the support last time.
We are facing another issue in our project while using go-python package.
It seems something related to python version and compatibility with
go-python package.
Issue Description
To simulate the issue I have python written as below
#!/bin/python
import sys
def PrintSysArgv():
print (sys.argv)
if __name__ == "__main__":
PrintSysArgv()
This python if I run from python CLI works fine as shown below
>python test.py
['test.py']
>
Now I have go program to invoke the same function PrintSysArgv as below
package main
import (
"<package>/gopy"
"fmt"
)
var funcNames = [...]string{
"PrintSysArgv",
}
var pyFuncs map[string]*gopy.PyFunction
func main() {
pyFuncs, err := gopy.Import("mymodule.test", funcNames[:]...)
if err != nil {
panic("Error importing python module")
}
_, err = pyFuncs["PrintSysArgv"].Call()
if err != nil {
panic(fmt.Sprintf("Error executing python function. error: %v",
err))
}
fmt.Println("Done")
}
Below is the snippet of gopy wrapper I am using in above go source
package gopy
import (
"errors"
"fmt"
"github.com/sbinet/go-python"
"reflect"
)
type PyFunction struct {
*python.PyObject
}
func (f *PyFunction) Call(args ...interface{}) (r *python.PyObject, err
error) {
var pyargs *python.PyObject
if pyargs, err = ToPyObject(reflect.ValueOf(args)); err != nil {
return
}
name := python.PyString_AsString(f.GetAttrString("__name__"))
if r = f.CallObject(pyargs); r == nil {
err = errors.New(fmt.Sprintf("%s(): function failed at
python side", name))
}
if pyobj := python.PyErr_Occurred(); pyobj != nil {
err = errors.New(fmt.Sprintf("%s(): exception happened in
python side", name))
python.PyErr_Clear()
}
return
}
var pyinit = false
func Init() (err error) {
if !pyinit {
if err = python.Initialize(); err == nil {
pyinit = true
}
}
return
}
func Import(module string, functions ...string) (funcs
map[string]*PyFunction, err error) {
if err = Init(); err != nil {
return
}
if pymod := python.PyImport_ImportModuleNoBlock(module); pymod ==
nil {
err = errors.New(fmt.Sprintf("gopy:%s: module import
failed", module))
} else {
funcs = make(map[string]*PyFunction)
for _, name := range functions {
if pyfunc := pymod.GetAttrString(name); pyfunc ==
nil {
err = errors.New(fmt.Sprintf("gopy:%s:%s:
function not found", module, name))
return
} else {
funcs[name] = &PyFunction{pyfunc}
}
}
}
return
}
The out of the execution of go program fails python side as shown below
go run test.go
panic: Error executing python function. error: PrintSysArgv(): exception
happened in python side
goroutine 1 [running]:
main.main()
/root/go/bin/test.go:22 +0x291
goroutine 17 [syscall, locked to thread]:
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:2232 +0x1
exit status 2
Just a wierd thought that go-python uses a trimmed version of python which
is not able to take care of "sys.argv" as such.
Can you please look into the same and suggest us accordingly.
If needed / suggested I can raise the same in wiki...
Thanks and Regards,
Shubhendu
On Thu, Jan 14, 2016 at 1:48 AM, Sebastien Binet [email protected]
wrote:
—
Reply to this email directly or view it on GitHub
#33 (comment).
from go-python.
hi,
please open a new issue,
thanks.
from go-python.
Thanks Sebastien.
Raised one at #36
Regards,
Shubhendu
On Tue, Feb 9, 2016 at 1:48 PM, Sebastien Binet [email protected]
wrote:
hi,
please open a new issue,
thanks.—
Reply to this email directly or view it on GitHub
#33 (comment).
from go-python.
Related Issues (20)
- Does it works on Centos7 i686 system? HOT 1
- go get report errors HOT 4
- panic when register callback from go into python as module HOT 1
- How to call a function of Go from python HOT 3
- After running go-python script for a while, the memory becomes larger and larger HOT 1
- How to build the environment required by go-golang under window
- panic when run multi goroutine HOT 3
- Error reporting for execute command under win10 HOT 3
- Hi,
- Question: Usable with WebAssembly (WASM)? HOT 1
- Documentation not displayed due to license restrictions. HOT 2
- Pandas and go Python are incompatible? HOT 9
- D:\go\project\src\github.com\sbinet\go-python\capi.go:33:32: could not determine kind of name for C.METH_OLDARGS
- Exception SystemError: '/builddir/build/BUILD/Python-2.7.5/Objects/classobject.c:521: bad argument to internal function'
- can i import python module like selenium to use inside golang code?
- Let's try it, python bindings cgo-less HOT 1
- Cannot pass Integer type to CallFunction
- go panic when multi thread HOT 1
- How to use cPickle loads or dump complicated data, like array, class object
- memory leak? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-python.