<jupyter_start><jupyter_text>AiiDA Status<jupyter_code>from __future__ import print_function

from IPython.display import display, clear_output
import ipywidgets as ipw
import threading
import time
import subprocess
def on_restart(b):
    with restart_out:
        clear_output()
        ! verdi daemon stop
        ! verdi daemon start
        ! sleep 1
        clear_output()

restart_out = ipw.Output()
btn_restart = ipw.Button(description="Restart Daemon")
btn_restart.on_click(on_restart)
display(btn_restart,restart_out)
allstates_check = ipw.Checkbox(description="Show all states", value=False)
daemonlog_check = ipw.Checkbox(description="Show daemon log", value=False)

countdown = ipw.IntProgress(value=0, max=9, description="update in")
display(ipw.HBox([countdown, allstates_check, daemonlog_check]))

info_out = ipw.Output()
info_out.layout.border ="2px solid black"
display(info_out)

def update_status():
    while(True):
        with info_out:
            clear_output()
            ! date
            print("\nverdi daemon status")
            ! verdi daemon status
            cmd = "\nverdi calculation list --past-days 1"
            if allstates_check.value:
                cmd += " --all-states"
            print(cmd)
            ! $cmd
            
            if daemonlog_check.value:
                print("\ngrep -i error aiida_daemon.log")
                ! tail -c 1000000 ~/.aiida/daemon/log/aiida_daemon.log | grep -i error

        for i in reversed(range(10)):
            countdown.value = i
            time.sleep(1)
# start after everything is setup otherwise widgets might endup in wrong output
threading.Thread(target=update_status).start()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09537741369221767, 'fraction_numerical': 0.008777062609713282, 'mean_word_length': 2.8687782805429864, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '40871', 'license': 'MIT', 'n_tokens_mistral': 544, 'n_tokens_neox': 525, 'n_words': 124, 'path': 'aiida_status.ipynb', 'repo_name': 'aiidalab/aiidalab-aiida-cockpit', 'size': '1709'}