Skip to content

Conversation

coderfengyun
Copy link
Contributor

Describe the changes you have made:

Problem I encountered: When I use the same Interpreter instance to complete multiple code-writing tasks in a row within a process, I try to use Interpreter.reset() to reset the context and Interpreter state between each task. However, after several runs, I ran into the problem of too many open file handles.

Solution I provide: So in this pr, Interpreter.reset closes the child process and closes its open file handles.

Reference any relevant issue (Fixes #000)

  • I have performed a self-review of my code:

I have tested the code on the following OS:

  • Windows
  • MacOS
  • Linux

AI Language Model (if applicable)

  • GPT4
  • GPT3
  • Llama 7B
  • Llama 13B
  • Llama 34B
  • Huggingface model (Please specify which one)

@coderfengyun coderfengyun changed the title MOD: close subprocess when reset MOD: close subprocess and its file handles when reset Sep 22, 2023
@AncalagonX
Copy link

Would this also be desired for %undo if there were new handle openings that were undone?

@coderfengyun
Copy link
Contributor Author

coderfengyun commented Sep 25, 2023

Would this also be desired for %undo if there were new handle openings that were undone?

I think if the code-interpreter subprocess is already started before %undo, whether to shut down this child process or not, depending on preferences for code.

  1. Pros: clearing has the obvious benefit of releasing the file handle ASAP. In this case, The question is equivalent to whether or not to reset the code-interpreter every time a single question in a chat is answered.
  2. Cons: not clearing speeds up the processing of the follow-up question in this chat session, and the file handle is eventually released when the chat session is closed or reset.

I would suggest a Chat session as a management unit to prevent certain context failures. But, eventually a decision needs to be made by the owner of this code repository.

Comment on lines 120 to 128

def stop(self):
"""
Stops the interpreter process.
"""
if self.proc:
self.proc.terminate()
self.proc.stdin.close()
self.proc.stdout.close()
Copy link
Collaborator

@ericrallen ericrallen Oct 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these changes probably need to move to interpreter/code_interpreters/subprocess_code_interpreter.py now that the code has been refactored.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course, I'll come back to modify this commit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about turning off stdin and stdout directly in the terminate method?

Comment on lines 197 to 198
for code_interpreter in self.code_interpreters.values():
code_interpreter.stop()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs to move to interpreter/core/core.py now that the codebase has been refactored.

@ericrallen
Copy link
Collaborator

Hey there, @coderfengyun!

I think this is a really great suggestion and am happy to help resolve the merge conflicts and move the code to the refactored codebase if you want to hand it off.

I think we just need to add the stdin and stdout calls to .close() to the existing terminate() handler.

@coderfengyun
Copy link
Contributor Author

coderfengyun commented Nov 9, 2023

Hey there, @coderfengyun!

I think this is a really great suggestion and am happy to help resolve the merge conflicts and move the code to the refactored codebase if you want to hand it off.

I think we just need to add the stdin and stdout calls to .close() to the existing terminate() handler.

Changes were made as per your REVIEW comments. @ericrallen @AncalagonX

@KillianLucas
Copy link
Collaborator

Great work @coderfengyun, very straightforward and helpful! Merging now, then renaming .proc to .process which is I believe the right property name.

Long time coming and I very much appreciate your edits post-refactor. Thank you @ericrallen for your work here too.

@KillianLucas KillianLucas merged commit d3c6da9 into openinterpreter:main Nov 15, 2023
@coderfengyun
Copy link
Contributor Author

Thanks to all the contributors to open-interpreter for giving us the opportunity to explore the use of code-interpreter. What I did was make a modest contribution.

joshuavial pushed a commit to joshuavial/open-interpreter that referenced this pull request Nov 16, 2023
MOD: close subprocess and its file handles when reset
Former-commit-id: d3c6da9
Former-commit-id: 8d162229bec7bdc656a40e21a6da37e563cc6329
Former-commit-id: 966267c33f55016cedee8552dcd77797701d81a1 [formerly 08860dd1f6b01ec0019e562aab8b339ebd5b97a9]
Former-commit-id: bcd10fa587b5d33067641f4bd9874571b7d0fd47
joshuavial pushed a commit to joshuavial/open-interpreter that referenced this pull request Nov 16, 2023
MOD: close subprocess and its file handles when reset
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

Successfully merging this pull request may close these issues.

4 participants