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

Child process not working in packaged app #427

Closed
kentezrabetita opened this issue Dec 5, 2023 · 7 comments
Closed

Child process not working in packaged app #427

kentezrabetita opened this issue Dec 5, 2023 · 7 comments
Assignees

Comments

@kentezrabetita
Copy link

Hello,

I am experiencing an issue related to the execution of a child process in the packaged version of my Nextron application. The child process works as expected in the development environment, but fails to execute when the application is packaged. I am currently testing on an M1 Mac.

The file structure in the main directory is as follows:

main/
├─ helpers/
├─ background.ts
├─ ipc.ts
├─ worker.ts

In my ipc.ts file, I fork a child process from worker.ts:

const child = fork('./main/worker.ts'); // i think the problem also lies here

child.on('message', (message) => {
  console.log('Received message from child:', message);
});

child.on('exit', (code) => {
  console.log(`Child process exited with code ${code}`);
});

export const setupIpcHandlers = () => { // this function is called in the `background.ts`
  ipcMain.on('store-image', async (event, image) => {
    const user: any = state.store.get('user_data');
    const { id } = user;

    if (child.connected) {
      child.send({ image: image, user_id: id });
    }
  });
}

In the worker.ts file, I handle the 'message' event from the main process:

process.on('message', async (message) => {
  // handles a basic HTTP request to upload image
});

In development, the main process successfully sends the message and the child process performs as expected. However, in the packaged app, the child process doesn't seem to be executing.

Despite adding 'exit' and 'error' event handlers to the child process, no error messages or exit codes have been generated.

Upon examining the built version of the app in the ./app directory, I noticed the absence of a worker.js file or other files that i've added. However, references to the worker code exist in background.js. This leads me to suspect that the issue might be related to the way I'm referencing the worker file in const child = fork('./main/worker.ts');.

Any guidance on this issue would be greatly appreciated, particularly on getting the child process to work correctly in the packaged app.

Thank you!

@bm777 bm777 self-assigned this Dec 5, 2023
@bm777
Copy link
Collaborator

bm777 commented Dec 5, 2023

Hi @kentezrabetita, I managed to include a child process running Python or Rust code via a call from IPC.

I'm about to push it tomorrow or Thursday in another branch, then do a PR to the examples folder of Nextron.

You will be able to use the analogy in .ts, .js easily, but for Python, you need to have Python or Rust installed on the target machine to ruin your app. As I said, if you only use js/ts, no need, it is already packed in Nextron, you just.

@kentezrabetita
Copy link
Author

Hey @bm777, that's awesome news! I appreciate your work on this and thanks for the good heads up. Looking forward to your PR!

@bm777
Copy link
Collaborator

bm777 commented Dec 7, 2023

@kentezrabetita Here is the example running Python code via IPC on top of the basic lang javascript example.

  • it handles dev mode and pro mode in the background.js
  • Waiting for the merge or review of the PR.
Screen.Recording.2023-12-07.at.01.39.08.mov

@JesTery58
Copy link

you not passed channel when called child.send()

@bm777
Copy link
Collaborator

bm777 commented Jan 25, 2024

@JesTery58 can you be more precise please?

@JesTery58
Copy link

do child.send() function want a channel ?

@bm777
Copy link
Collaborator

bm777 commented Jan 25, 2024

@JesTery58 basically when using IPC, I always pass the channel as str, in this case, the channel was : here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants