<commit_before>package policy

import (
	"os"
	"strconv"
	"sync"

	sb "github.com/open-lambda/open-lambda/worker/sandbox"
)

type ForkServer struct {
	Sandbox  sb.ContainerSandbox
	Pid      string
	SockPath string
	Packages map[string]bool
	Hits     float64
	Parent   *ForkServer
	Children int
	Runners  bool
	Size     float64
	Mutex    *sync.Mutex
}

func (fs *ForkServer) Hit() {
	curr := fs
	for curr != nil {
		curr.Hits += 1.0
		curr = curr.Parent
	}

	return
}

func (fs *ForkServer) Kill() error {
	if fs.Parent == nil {
		panic("attempted to kill the root")
	}

	pid, err := strconv.Atoi(fs.Pid)
	if err != nil {
		return err
	}

	proc, err := os.FindProcess(pid)
	if err != nil {
		return err
	}

	proc.Kill()

	fs.Sandbox.Stop()
	fs.Sandbox.Remove()
	fs.Parent.Children -= 1

	return nil
}<commit_msg>kill cache containers in background<commit_after>package policy

import (
	"os"
	"strconv"
	"sync"

	sb "github.com/open-lambda/open-lambda/worker/sandbox"
)

type ForkServer struct {
	Sandbox  sb.ContainerSandbox
	Pid      string
	SockPath string
	Packages map[string]bool
	Hits     float64
	Parent   *ForkServer
	Children int
	Runners  bool
	Size     float64
	Mutex    *sync.Mutex
}

func (fs *ForkServer) Hit() {
	curr := fs
	for curr != nil {
		curr.Hits += 1.0
		curr = curr.Parent
	}

	return
}

func (fs *ForkServer) Kill() error {
	if fs.Parent == nil {
		panic("attempted to kill the root")
	}

	pid, err := strconv.Atoi(fs.Pid)
	if err != nil {
		return err
	}

	proc, err := os.FindProcess(pid)
	if err != nil {
		return err
	}

	proc.Kill()

	go func() {
		fs.Sandbox.Stop()
		fs.Sandbox.Remove()
	}()
	fs.Parent.Children -= 1

	return nil
}
{'fraction_non_alphanumeric': 0.12259615384615384, 'fraction_numerical': 0.008413461538461538, 'mean_word_length': 2.9928057553956835, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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}}
{'dir': 'git-commits-cleaned', 'id': '1677066', 'n_tokens_mistral': 699, 'n_tokens_neox': 655, 'n_words': 168}