<commit_before>use env::{MultiEnv, MultiEnvDiscrete};
use features::{MultiEnvObserve};

use stopwatch::{Stopwatch};

use rand::{Rng};
use std::cell::{Cell};
//use std::rc::{Rc};
//use std::sync::{Arc};
use std::sync::mpsc::{SyncSender, Receiver, RecvTimeoutError, sync_channel};
use std::thread::{JoinHandle, spawn};
use std::time::{Duration};

#[derive(Clone, Copy, Debug)]
pub enum MonitorAction {
  CtrlStop,
  StartEvent(MonitorEvent),
  EndEvent(MonitorEvent),
}

#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum MonitorEvent {
  Shutdown,
  Construct,
  Reset,
  Step,
  IsTerminal,
  GetNumPlayers,
  GetIsActivePlayer,
  GetIsLegalAction,
  Observe,
}

pub struct MonitorWorker {
  //stopwatch:    Stopwatch,
  rx:   Receiver<(u64, MonitorAction)>,
  active_event: Option<(u64, MonitorEvent)>,
}

impl MonitorWorker {
  pub fn runloop(&mut self) {
    loop {
      match self.rx.recv_timeout(Duration::from_millis(5000)) {
        Err(RecvTimeoutError::Timeout) => {
          if let Some((tick, event)) = self.active_event {
            panic!("PANIC: MonitorEnv: timed out during an event: {} {:?}",
                tick, event);
          }
        }
        Err(RecvTimeoutError::Disconnected) => {
          break;
        }
        Ok((tick, action)) => {
          match action {
            MonitorAction::CtrlStop => {
              break;
            }
            MonitorAction::StartEvent(event) => {
              assert!(self.active_event.is_none());
              self.active_event = Some((tick, event));
            }
            MonitorAction::EndEvent(event) => {
              assert!(self.active_event.is_some());
              assert_eq!(self.active_event.unwrap().0, tick);
              assert_eq!(self.active_event.unwrap().1, event);
              self.active_event = None;
            }
          }
        }
      }
    }
  }
}
<commit_msg>`MonitorEnv` worker timeout panic message.<commit_after>use env::{MultiEnv, MultiEnvDiscrete};
use features::{MultiEnvObserve};

use stopwatch::{Stopwatch};

use rand::{Rng};
use std::cell::{Cell};
//use std::rc::{Rc};
//use std::sync::{Arc};
use std::sync::mpsc::{SyncSender, Receiver, RecvTimeoutError, sync_channel};
use std::thread::{JoinHandle, spawn};
use std::time::{Duration};

#[derive(Clone, Copy, Debug)]
pub enum MonitorAction {
  CtrlStop,
  StartEvent(MonitorEvent),
  EndEvent(MonitorEvent),
}

#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum MonitorEvent {
  Shutdown,
  Construct,
  Reset,
  Step,
  IsTerminal,
  GetNumPlayers,
  GetIsActivePlayer,
  GetIsLegalAction,
  Observe,
}

pub struct MonitorWorker {
  //stopwatch:    Stopwatch,
  rx:   Receiver<(u64, MonitorAction)>,
  active_event: Option<(u64, MonitorEvent)>,
}

impl MonitorWorker {
  pub fn runloop(&mut self) {
    loop {
      match self.rx.recv_timeout(Duration::from_millis(5000)) {
        Err(RecvTimeoutError::Timeout) => {
          if let Some((tick, event)) = self.active_event {
            panic!("PANIC: MonitorWorker: timed out during an event: {} {:?}",
                tick, event);
          }
        }
        Err(RecvTimeoutError::Disconnected) => {
          break;
        }
        Ok((tick, action)) => {
          match action {
            MonitorAction::CtrlStop => {
              break;
            }
            MonitorAction::StartEvent(event) => {
              assert!(self.active_event.is_none());
              self.active_event = Some((tick, event));
            }
            MonitorAction::EndEvent(event) => {
              assert!(self.active_event.is_some());
              assert_eq!(self.active_event.unwrap().0, tick);
              assert_eq!(self.active_event.unwrap().1, event);
              self.active_event = None;
            }
          }
        }
      }
    }
  }
}

{'fraction_non_alphanumeric': 0.14583333333333334, 'fraction_numerical': 0.005274261603375527, 'mean_word_length': 2.5581613508442778, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, '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': '2171309', 'n_tokens_mistral': 1174, 'n_tokens_neox': 1186, 'n_words': 218}