Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to import (use) pythonia #4236

Open
codehz opened this issue Aug 21, 2023 · 7 comments
Open

Unable to import (use) pythonia #4236

codehz opened this issue Aug 21, 2023 · 7 comments
Labels
enhancement New feature or request node.js Compatibility with Node.js APIs

Comments

@codehz
Copy link
Contributor

codehz commented Aug 21, 2023

What version of Bun is running?

0.7.3

What platform is your computer?

Darwin 22.5.0 arm64 arm

What steps can reproduce the bug?

code:

import { python } from "pythonia";

console.log(await python('json'))

What is the expected behavior?

run without problem

What do you see instead?

28 |     // internal V8 serialization APIs; fast but unusable in Python.
29 |     // See https://github.com/nodejs/node/issues/39317
30 |     const symbols = Object.getOwnPropertySymbols(this.proc)
31 |     const symbol = symbols.find(sym => sym.toString() === 'Symbol(kChannelHandle)')
32 |     const channel = this.proc[symbol]
33 |     channel._writeUtf8String = channel.writeUtf8String
                                   ^
TypeError: undefined is not an object (evaluating 'channel.writeUtf8String')

Additional information

related code:
https://github.com/extremeheat/JSPyBridge/blob/1e7a6a4a8193eeb8af3fab5587c2ea6da576b130/src/pythonia/IpcPipeCom.js#L22-L44

@codehz codehz added the bug Something isn't working label Aug 21, 2023
@Hanaasagi
Copy link
Collaborator

Related to IPC channel, https://nodejs.org/api/process.html#processchannel

const cp = require("node:child_process");
const assert = require("node:assert");

if (process.argv[2] === "child") {
  setTimeout(() => { }, 100);
} else {
  const child = cp.spawn(process.execPath, [__filename, "child"], { stdio: [null, null, null, "ipc"] });
  console.log(child.channel);
}

@AaronDewes
Copy link
Contributor

Is compatibility with packages that rely on V8 internals even a goal for Bun?

@birkskyum
Copy link
Collaborator

Is compatibility with packages that rely on V8 internals even a goal for Bun?

there was some talk about this in here #4259 (comment)

@codehz
Copy link
Contributor Author

codehz commented Sep 3, 2023

Is compatibility with packages that rely on V8 internals even a goal for Bun?

I think it is node’s internal, not v8, since no native module used here

@AaronDewes
Copy link
Contributor

Is compatibility with packages that rely on V8 internals even a goal for Bun?

I think it is node’s internal, not v8, since no native module used here

I was just saying that because of the comment in pythonia's code which says "internal V8 serialization APIs; fast but unusable in Python."

@codehz
Copy link
Contributor Author

codehz commented Sep 3, 2023

I was just saying that because of the comment in pythonia's code which says "internal V8 serialization APIs; fast but unusable in Python."

oh, it is not complete, the whole comment is

BAD HACK: since the channel is not exposed, and we need to send JSON with a custom serializer, we basically have two choices:

  1. either JSON.stringify it with a custom encoder in our lib, then have it JSON.stringified again in the Node.js standard lib, then unwrapped twice in Python, or
  2. use a hack to get the low level IPC API and write raw strings to it.

There is no 'string' serialization option for IPC. It's either JSON or 'Advanced' which uses internal V8 serialization APIs;

so it basically saying, pythonia cannot use node’s ipc channel directly and there no api to pass a custom channel (without break stdio), so they have to hijack the default ipc channel’s serialization mechanism

@codehz codehz mentioned this issue Sep 4, 2023
13 tasks
@robobun robobun added the node.js Compatibility with Node.js APIs label Sep 9, 2023
@paperdave paperdave added enhancement New feature or request and removed bug Something isn't working labels Feb 6, 2024
@paperdave
Copy link
Member

We are not going to implement Symbol(kChannelHandle) (an internal node.js symbol) for bun.

but maybe we can add an alternative text mode as proposed in nodejs/node#39317 (this issue was closed for inactivity)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request node.js Compatibility with Node.js APIs
Projects
None yet
Development

No branches or pull requests

6 participants