如何在Go应用程序中创建多个Python实例

huangapple go评论76阅读模式
英文:

How to create multiple Python's instances within a Go application

问题

我目前正在使用Golang进行一个项目,需要调用Python。

在Python中,有一个类似单例模式的库。

但是我不能修改这些库,因为它们对我来说太复杂了。

我能做的大部分事情就是用我的Python脚本包装它。

所以我正在寻找一种在Go中创建多个Python解释器的方法。

或者在Python中创建多个子解释器。

这意味着我可以创建多个Python实例(相同的应用程序)。

有没有办法可以做到这一点?

英文:

Currently I'm doing a project in Golang which need to call to Python.

In Python it's a library of singleton-like instance.

But I can't modify those library because It's too complicated. (for me)

Most thing I can do is wrap it with my own Python script.

So I'm finding a way to create multiple Python interpreter in Go.

Or maybe multiple sub-interpreter in Python.

Which mean I can create many python instance(same application).

Any ways I can do this?

答案1

得分: 0

根据Chris Townsend和pie-o-pah的说法,

尝试实现子解释器会更加复杂。

尝试创建语言接口对我的情况很有意义。

在这种情况下,os/exec是正确的方法。

如果我的主服务器负载过重,甚至可以创建SSH连接到远程的Python模块。

英文:

As Chris Townsend and pie-o-pah said,

Trying to implement sub-interpreter is much more complicate.

Try to create the language interface is make senses to my case.

In this situation os/exec is the way to go.

And can even create ssh to remote my python module if my main server is overload.

huangapple
  • 本文由 发表于 2015年12月11日 21:04:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/34224258.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定