TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Node.js and Python Interoperability

94 点作者 fridgamarator将近 6 年前

7 条评论

swordfeng将近 6 年前
I was once trying to do something even crazier: exposing full python accessibility to node.js, using proxies. So that you can use python objects and functions as native javascript objects and functions. It is feasible because the languages and runtimes share a number of common designs.<p>There were several tough things however. The first was error handling. Yes you can catch exceptions in native code and convert it to exceptions in the other language, but it&#x27;s not straightforward to keep stacktraces. The second was circular references between runtimes. Since references across boundaries are global, garbage collector on either side could not reclaim circularly referenced objects. Although this could be resolved by manually breaking up the circle, it could be better to have weak references. (Or maybe other utilities, idk what would be more elegant.) The third was that js has no operator overloading, so I had to use .__add__() for example to call the python add operator.<p>One line example: <a href="https:&#x2F;&#x2F;github.com&#x2F;swordfeng&#x2F;pyjs&#x2F;blob&#x2F;master&#x2F;test&#x2F;jsobject.js#L60" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;swordfeng&#x2F;pyjs&#x2F;blob&#x2F;master&#x2F;test&#x2F;jsobject....</a> It&#x27;s a toy project I did years ago and not even compiling now. Also I was wondering if anyone really need to do things in this way, given there are bunch of popular and stable RPC libraries. But I was happy to learn something about underlying cpython and v8 from it.
评论 #20195200 未加载
评论 #20194670 未加载
rkeene2将近 6 年前
I recently did something similar with Tcl (instead of Python) and Duktape (instead of V8): <a href="https:&#x2F;&#x2F;rkeene.dev&#x2F;js-repl&#x2F;" rel="nofollow">https:&#x2F;&#x2F;rkeene.dev&#x2F;js-repl&#x2F;</a><p>All the Tcl runtime is in the &quot;runtime&quot; object, so like &quot;runtime.puts(&#x27;Hello World&#x27;)&quot; or &quot;runtime.expr(&#x27;2<i></i>128&#x27;)&quot;, etc<p>It was a lot of fun
评论 #20193976 未加载
lmeyerov将近 6 年前
We needed to solve this as part of using pydata&#x2F;GPU service calls from our node app. While we do have a couple of native modules, they&#x27;re a PITA. Our solution for more generic code is async HTTP service calls passing typed Apache Arrow tables ( <a href="https:&#x2F;&#x2F;arrow.apache.org&#x2F;docs&#x2F;js&#x2F;" rel="nofollow">https:&#x2F;&#x2F;arrow.apache.org&#x2F;docs&#x2F;js&#x2F;</a> ), which gives a cleaner path to maintenance, observability, packaging, distribution, low overhead etc.<p>The current trick we&#x27;re looking at is making this zero-copy when same-node, esp for GPU code, so happy to chat with folks about that!
snek将近 6 年前
Very cool idea! For all of you thinking of writing native modules for node, please remember to use napi, not nan. napi is fully abi stable, while nan is not!<p><a href="https:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;n-api.html" rel="nofollow">https:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;n-api.html</a><p>We also have a c++ wrapper: <a href="https:&#x2F;&#x2F;github.com&#x2F;nodejs&#x2F;node-addon-api" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;nodejs&#x2F;node-addon-api</a>
santa_boy将近 6 年前
I&#x27;m having the requirement to work with Node and Python now. I write my webapps in node but have data analytics scripts written in python to be invoked. I&#x27;m planning to use [python-shell - npm](<a href="https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;python-shell" rel="nofollow">https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;python-shell</a>)
评论 #20194447 未加载
评论 #20196451 未加载
fermigier将近 6 年前
Also: <a href="https:&#x2F;&#x2F;github.com&#x2F;bobpepin&#x2F;pyduktape" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;bobpepin&#x2F;pyduktape</a> (interop between the Duktape JS interpreter - <a href="https:&#x2F;&#x2F;duktape.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;duktape.org&#x2F;</a> - and Python).
rcfox将近 6 年前
I&#x27;ve worked the opposite way: calling Javascript from Python, using PyV8. It worked okay enough, but it felt super fragile. We only used it to run a tiny bit of client-side code on the server. I wouldn&#x27;t want to have a large project where Javascript and Python interact heavily.
评论 #20194249 未加载