echogarden-project / echogarden

Easy-to-use speech toolset. Written in TypeScript. Includes tools for synthesis, recognition, alignment, speech translation, language detection, source separation and more.
GNU General Public License v3.0
173 stars 17 forks source link

I have a question with the running #38

Closed yhown589 closed 7 months ago

yhown589 commented 7 months ago

When I finish running the code, the program should be stop. like I run console.log("hello world"), when this code finish running, the program will stop and exist. but in my webStrom run icon, it will look like the picture shows:

PixPin_2024-02-23_19-54-03

it must manually click stop icon. I mean, are there other component alway keep running? Jsut like express module

rotemdan commented 7 months ago

In general, if you are using Echogarden as a library, and not starting any subprocess or server, and properly using await to wait for all promises to finish, then it should exit normally when it finishes.

Echogarden uses a lot of async operations, so it's possible some of them didn't complete.

Also, there is some functionality in Echogarden which starts in a separate process, starts a server, or that opens connections to a remote server, which can cause this, but I can't know exactly what you are doing. Here's what the Google Gemini chatbot says about it:

Why doesn't it end by itself sometimes?

Node.js is event-driven, meaning it processes tasks in its event loop. If your process has pending tasks, even asynchronous ones, it won't exit automatically. This can happen in several scenarios:

Unhandled promises or async/await: If your code has unresolved promises or unfinished async/await operations, the event loop won't be empty, preventing automatic exit. Long-running tasks: If your code has tasks that take a long time, like long-running network requests, the process won't exit until they finish. Event listeners: If you have event listeners that keep adding tasks to the event loop, the process won't exit.

In general, when Node.js is prevented from exiting due to any of these reasons, you can try using process.exit() to force it to exit.

yhown589 commented 7 months ago

in the new nodejs project, I only install echogarden module. I create the de.js in this new project and only type the following code in de.js: import * as Echogarden from 'echogarden' I set a debugger in this code

PixPin_2024-02-23_23-00-08

click step into, the terminal look likes the picture shows:

PixPin_2024-02-23_22-54-42

I aceess this url, and then look like:

PixPin_2024-02-23_23-02-27

Maybe it’s because of websocket that the program keeps running. Not only import * as Echogarden from 'echogarden', the URL of WebSockets will appear. As long as echogarden is introduced, the URL of WebSockets will appear.

Does echogarden introduced components releated to the "WebSockets"?

rotemdan commented 7 months ago

Thanks for the report!

I can reproduce this. At first I didn't know why this is happening. Using elimination, I found out it is caused by a the Synthesis module importing a method from the Worker model:

import { shouldCancelCurrentTask } from "../server/Worker.js";

This caused the worker module to be loaded whenever the library is loaded. The message channel started by the worker module, when it's loaded, is preventing the loading process to terminate, apparently. No actual worker is started, though. It's just the message channel.

I did not intend that to happen. I will try to fix this soon. I'm working on it now.

rotemdan commented 7 months ago

I published version 0.11.19 to npm, which should fix the issue.

I moved the message channel initialization code to a function, which is now only called when needed.

yhown589 commented 7 months ago

I updated the last version and it doesn't occur this problem, thank you for the quick fix and update