<commit_before>package main

import (
	"os"
	"os/signal"
	"syscall"
	"time"

	log "github.com/Sirupsen/logrus"
	//"github.com/robinmonjo/dock/system"
)

const (
	signalBufferSize       = 2048
	childrenSigtermTimeout = 2  //seconds
	childrenKillTimeout    = 10 //seconds
)

type signalsListener struct {
	signals chan os.Signal
}

func newSignalsListener() *signalsListener {
	s := make(chan os.Signal, signalBufferSize)
	signal.Notify(s)

	return &signalsListener{
		signals: s,
	}
}

func (l *signalsListener) forward(p *process) int {

	cpid := p.pid()
	//procStatus, err := system.NewProcStatus(cpid)
	//if err != nil {
	//	log.Error(err)
	//}

	for s := range l.signals {
		log.Debug(s)
		switch s {
		case syscall.SIGCHLD:
			//child exited, sending a sigterm to all pses and collecting waits TODO: kill timeout
			if os.Getpid() == 1 { //if i'am the init process (supposed to be but I crashed my mac twice :) )
				go func() {
					<-time.After(childrenSigtermTimeout * time.Second)
					syscall.Kill(-1, syscall.SIGTERM)
				}()
			}

			exits, err := l.reap()
			if err != nil {
				log.Error(err)
			}
			for _, e := range exits {
				if e.pid == cpid {
					p.wait()
					return e.status<commit_msg>kill timeout<commit_after>package main

import (
	"os"
	"os/signal"
	"syscall"
	"time"

	log "github.com/Sirupsen/logrus"
	//"github.com/robinmonjo/dock/system"
)

const (
	signalBufferSize    = 2048
	childrenTermTimeout = 2  //seconds
	childrenKillTimeout = 10 //seconds
)

type signalsListener struct {
	signals chan os.Signal
}

func newSignalsListener() *signalsListener {
	s := make(chan os.Signal, signalBufferSize)
	signal.Notify(s)

	return &signalsListener{
		signals: s,
	}
}

func (l *signalsListener) forward(p *process) int {

	cpid := p.pid()
	//procStatus, err := system.NewProcStatus(cpid)
	//if err != nil {
	//	log.Error(err)
	//}

	for s := range l.signals {
		log.Debug(s)
		switch s {
		case syscall.SIGCHLD:
			done := make(chan bool, 1)
			if os.Getpid() == 1 { //if i'am the init process (supposed to be but I crashed my mac twice :) )
				go func() {
					timeouts := []time.Duration{childrenTermTimeout, childrenKillTimeout}
					sigs := []syscall.Signal{syscall.SIGTERM, syscall.SIGKILL}
					for i := 0; i < 2; i++ {
						select {
						case <-time.After(timeouts[i] * time.Second):
							syscall.Kill(-1, sigs[i])
						case <-done:
							return
						}
					}
				}()
			}

			exits, err := l.reap()
			done <- true
			if err != nil {
				log.Error(err)
			}
			for _, e := range exits {
				if e.pid == cpid {
					p.wait()
					return e.status
{'fraction_non_alphanumeric': 0.14109006571318128, 'fraction_numerical': 0.008117510630073444, 'mean_word_length': 2.8002936857562406, 'pattern_counts': {'":': 0, '<': 8, '<?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': '6216776', 'n_tokens_mistral': 1137, 'n_tokens_neox': 938, 'n_words': 239}