use thread pool to avoid zombie processes
Some checks reported errors
continuous-integration/drone/push Build was killed
Some checks reported errors
continuous-integration/drone/push Build was killed
This commit is contained in:
@@ -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ḱ!");
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user