Skip to content

#90 check notebook and terminal sessions #114

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

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

takeru1205
Copy link

Issue #, if available:
Issue: #90

Description of changes:
The current sample lifecycle configuration only checks for notebook sessions. I have updated it to also monitor terminal sessions. This enhancement is vital as the instance will not stop if there are any non-idle notebook sessions.

Testing Done

  • Notebook Instance created successfully with the Lifecycle Configuration
  • Notebook Instance stopped and started successfully
  • [NA] Documentation in the script around any network access requirements
  • [NA] Documentation in the script around any IAM permission requirements
  • CLI commands used to validate functionality on the instance
  • [NA] New script link and description added to README.md

Idle time is set to 10 minutes.

*/5 * * * * /home/ec2-user/anaconda3/bin/python3 /tmp/autostop.py --time 600 --ignore-connections>> /var/log/jupyter.log

Logs showing kernel activity:

  | 2023-12-12T11:52:04.602+09:00 | [I 2023-12-12 02:51:59.963 ServerApp] New terminal with automatic name: 1
  | 2023-12-12T11:52:20.603+09:00 | [I 2023-12-12 02:52:15.685 ServerApp] New terminal with automatic name: 2
  | 2023-12-12T11:55:02.391+09:00 | Kernel is not idle. Last activity time = 2023-12-12 02:51:43.955000
  | 2023-12-12T11:55:02.391+09:00 | Notebook idle state set as False since no sessions detected.
  | 2023-12-12T11:55:02.391+09:00 | {'name': '1', 'last_activity': '2023-12-12T02:53:44.396492Z'}
  | 2023-12-12T11:55:02.391+09:00 | Kernel is not idle. Last activity time = 2023-12-12 02:53:44.396492
  | 2023-12-12T11:55:02.391+09:00 | {'name': '2', 'last_activity': '2023-12-12T02:53:00.323036Z'}
  | 2023-12-12T11:55:02.391+09:00 | Kernel is not idle. Last activity time = 2023-12-12 02:53:00.323036
  | 2023-12-12T11:55:06.602+09:00 | Kernel not idle. Pass.
  | 2023-12-12T12:00:01.980+09:00 | Kernel is not idle. Last activity time = 2023-12-12 02:51:43.955000
  | 2023-12-12T12:00:01.980+09:00 | Notebook idle state set as False since no sessions detected.
  | 2023-12-12T12:00:01.980+09:00 | {'name': '1', 'last_activity': '2023-12-12T02:53:44.396492Z'}
  | 2023-12-12T12:00:01.980+09:00 | Kernel is not idle. Last activity time = 2023-12-12 02:53:44.396492
  | 2023-12-12T12:00:01.980+09:00 | {'name': '2', 'last_activity': '2023-12-12T02:55:38.896191Z'}
  | 2023-12-12T12:00:01.980+09:00 | Kernel is not idle. Last activity time = 2023-12-12 02:55:38.896191
  | 2023-12-12T12:00:06.602+09:00 | Kernel not idle. Pass.
  | 2023-12-12T12:05:02.021+09:00 | Kernel is idle. Last activity time = 2023-12-12 02:51:43.955000

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@takeru1205 takeru1205 changed the title Feature/90 check notebook terminal sessions #90 check notebook and terminal sessions Dec 12, 2023
@dmlause
Copy link
Contributor

dmlause commented Mar 1, 2024

Thank you for raising this PR! Could you test this again please since it has been some time since this was originally raised?

@gusmann
Copy link

gusmann commented Jan 7, 2025

We experienced an issue with the current version of autostop.py recently and replaced our lifecycle config to use this version. Looks like it works as intended, thank you!

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.

3 participants