use thread pool to avoid zombie processes
Some checks reported errors
continuous-integration/drone/push Build was killed

This commit is contained in:
shimunn
2019-05-16 20:48:50 +02:00
parent 3cdee28f92
commit cb138358ce
3 changed files with 25 additions and 2 deletions

View File

@@ -4,6 +4,7 @@ use std::path::PathBuf;
use std::process::Command;
use std::thread;
use std::time::SystemTime;
use threadpool::ThreadPool;
pub trait EventListener {
fn name(&self) -> &'static str;
@@ -87,11 +88,13 @@ impl EventListener for LogListener {
pub struct ScriptListener {
pub script: PathBuf,
pub pool: ThreadPool,
}
impl ScriptListener {
pub fn new(script: PathBuf) -> ScriptListener {
ScriptListener { script }
let pool = ThreadPool::new(4);
ScriptListener { script, pool }
}
fn peer_props<'a>(&self, peer: &'a Peer) -> String {
@@ -136,7 +139,7 @@ impl ScriptListener {
fn call_sub<'a>(&self, args: Vec<&'a str>) {
let mut cmd = self.mkcmd(args);
thread::spawn(move || {
self.pool.execute(move || {
cmd.spawn().expect("Failed to call Script hooḱ!");
});
}