Closed sgehrman closed 1 year ago
I think its cool that this project is getting used in apps! :)
The chat has by default:
Runs default in interactive and continuous mode.
--run-once disable continuous mode
--no-interactive disable interactive mode altogether (uses given prompt only)
which means that it's running an infinite while
loop waiting for stdin
input. So yeah, you're right about the endless loop :) When you close your app, your app needs to send the chat a quit message too:
Type 'quit', '/quit', 'exit', '/exit' to quit
This makes sure that the chat closes all open threads and frees the model and all the pointers pointing to the model in memory. It should send a normal c++ closing code 0
when it closes properly. Something like this if all goes well exit:entry chat (pid: 8620) exited with return value 0
For testing, you could try the run-once and no-interactive flags to make sure that the chat runs just once and closes inside your app properly.
Oh.
I just learned that in linux and mac there's a SIGHUP signal when the parent app closes but in windows its something else. I don't currently handle any of those things. Which is the reason the chat app stays running after you close the parent process.
If its not too complicated, I'll try to add elementary signal handling in the future versions. I think that could be useful for people.
Thanks for bringing up this issue! :)
Thanks. I'm now trying to see if I can link the code with my app rather than using it as a process, but I can't figure it out yet.
This hopefully works now with v0.3.0. I did add the signal handling but I haven't made a parent app so I haven't been able to test it in practice.
I just tested this on a mac using a simple python script as the parent program and looks like it works with the newest version v0.3.0. If I close the script, it will also close "./chat" program.
I have an app and I added a feature to launch this 'chat' tool as a separate process and I send it stdin and parse stdout.
It works great, but if I quit my app, the chat process keeps running and the cpu goes to 80%.
It seems to get stuck in an endless loop when stdin goes down, but I haven't looked at it that carefully.