sbinet / go-python

naive go bindings to the CPython2 C-API
Other
1.52k stars 138 forks source link

the python class can not initialize #88

Closed DyncKevin closed 5 years ago

DyncKevin commented 5 years ago

i am using AnsiblePlaybook by python, i want to invoke method with golang. the python program run well, but when i call python methon in go it can not work well, and I have no idea what to do and how. this is the brief python file test.py

`

!/home/dync/pyvenv2.7/bin/python

import json, time from pprint import pprint from ansible.parsing.dataloader import DataLoader from ansible.executor.task_queue_manager import TaskQueueManager from ansible.executor.playbook_executor import PlaybookExecutor from ansible.plugins.callback import CallbackBase

def runbook(): print(PlaybookExecutor()) ### this line could not work well, PlaybookExecutor cannot initialized print("sleep 3 second...") time.sleep(3) return "heiheihei" ` the class PlaybookExecutor can be found.

in golang, i write like this: ` runbook := module.GetAttrString("runbook") if runbook == nil { log.Fatal("could not getattr 'runbook'") } defer runbook.DecRef() fmt.Println("runbook func get here...") fmt.Println(runbook) ok := runbook.Check_Callable() fmt.Println("call able,,ok:", ok)

//args = "-vvvv"
o1 := runbook.CallFunction() ### this line doesn't work well
if o1 == nil {
    log.Fatal("could not call 'anpb.runbook()'")
}

` runbook.CallFunction() will call python function runbook() I debug with golang, and find the python class PlaybookExecutor could not initialize, if I remove PlaybookExecutor it work well. by the way, the class DataLoader can initialize well. now, I don't know why and how to do. anyone could help me ?