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

clearing the workspace after completed session. #201

Open
gdssingh7 opened this issue Feb 8, 2024 · 4 comments
Open

clearing the workspace after completed session. #201

gdssingh7 opened this issue Feb 8, 2024 · 4 comments

Comments

@gdssingh7
Copy link

I would like to understand if we can flush the workspace after a session. if I deploy this application now. the workspace keep on filling the memory. Is there a way we can empty the workspace periodically.
Please let me know how can i do it. Thanks

@liqul
Copy link
Contributor

liqul commented Feb 18, 2024

@gdssingh7 Hi, could you clarify a bit on the 'workspace' in your question? is it the session data stored on disk under the project/workspace/ folder or you mean the memory spent for each new session?

@gdssingh7
Copy link
Author

yeah @liqul it's about the session data stored in Disk.

@twtester2
Copy link

@gdssingh7

The files are located in directories inside project/workspace/sessions.

When TaskWeaver is not running, I was able to delete them with the following script:

session_dir = "project/workspace/sessions"

    for filename in os.listdir(session_dir):
        file_path = os.path.join(session_dir, filename)
        try:
            if os.path.isfile(file_path) or os.path.islink(file_path):
                os.unlink(file_path)
            elif os.path.isdir(file_path):
                shutil.rmtree(file_path)
        except Exception as e:
            print('Failed to delete %s. Reason: %s' % (file_path, e))

However, when TaskWeaver is running and the session is created, the files are unable to be deleted because the kernel continues to run while logging remains in usage. I found that making the following change to lines 74-79 of taskweaver/code_interpreter/code_executor.py will end the kernels:

result = self.exec_client.execute_code(exec_id, code)

if result.is_success:
    self.stop()

    for artifact in result.artifact:

which makes it possible to delete the session files using the above code. These changes don't appear to break TaskWeaver, so it seems to accomplish clearing the workspace.

@liqul, do you think it makes sense to add "self.stop()" above to code_executor.py?

Thanks,
--TWT

@liqul
Copy link
Contributor

liqul commented Mar 11, 2024

@gdssingh7

The files are located in directories inside project/workspace/sessions.

When TaskWeaver is not running, I was able to delete them with the following script:

session_dir = "project/workspace/sessions"

    for filename in os.listdir(session_dir):
        file_path = os.path.join(session_dir, filename)
        try:
            if os.path.isfile(file_path) or os.path.islink(file_path):
                os.unlink(file_path)
            elif os.path.isdir(file_path):
                shutil.rmtree(file_path)
        except Exception as e:
            print('Failed to delete %s. Reason: %s' % (file_path, e))

However, when TaskWeaver is running and the session is created, the files are unable to be deleted because the kernel continues to run while logging remains in usage. I found that making the following change to lines 74-79 of taskweaver/code_interpreter/code_executor.py will end the kernels:

result = self.exec_client.execute_code(exec_id, code)

if result.is_success:
    self.stop()

    for artifact in result.artifact:

which makes it possible to delete the session files using the above code. These changes don't appear to break TaskWeaver, so it seems to accomplish clearing the workspace.

@liqul, do you think it makes sense to add "self.stop()" above to code_executor.py?

Thanks, --TWT

Thanks for providing a solution of deleting the files. However, I didn't quite understand the purpose of deleting a session folder of a running session.

If you don't need to review the session files, adding the deletion logic inside TaskWeaverApp.stop_session would be a better choice.

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