Skip to content

Commit

Permalink
Kill child process using signals
Browse files Browse the repository at this point in the history
  • Loading branch information
roquelopez committed Nov 14, 2023
1 parent e65da04 commit 66dea64
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
6 changes: 3 additions & 3 deletions alpha_automl/automl_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def _search_pipelines(self, automl_hyperparams):

if result == 'DONE':
search_process.terminate()
search_process.join(30)
search_process.join(10)
logger.debug(f'Found {found_pipelines} pipelines')
logger.debug('Search done')
break
Expand All @@ -93,10 +93,10 @@ def _search_pipelines(self, automl_hyperparams):
yield {'pipeline': pipeline, 'message': 'SCORED'}

if time.time() > search_start_time + self.time_bound:
logger.debug('Reached search timeout')
search_process.terminate()
search_process.join(30)
search_process.join(10)
logger.debug(f'Found {found_pipelines} pipelines')
logger.debug('Reached search timeout')
break

def check_automl_hyperparams(self, automl_hyperparams):
Expand Down
27 changes: 11 additions & 16 deletions alpha_automl/pipeline_synthesis/setup_search.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import logging
import os
import sys
import signal
import logging
from os.path import join

from alpha_automl.grammar_loader import load_automatic_grammar, load_manual_grammar
from alpha_automl.pipeline import Pipeline
from alpha_automl.pipeline_search.Coach import Coach
Expand Down Expand Up @@ -41,22 +42,16 @@
}


def signal_handler(queue, signum):
logger.debug(f'Receiving signal {signum}, terminating process')
queue.put('DONE')
# TODO: Should it save the last status of the NN model?
sys.exit(0)


def search_pipelines(
X,
y,
scoring,
splitting_strategy,
task_name,
time_bound,
automl_hyperparams,
metadata,
output_folder,
verbose,
queue,
):

def search_pipelines(X, y, scoring, splitting_strategy, task_name, time_bound, automl_hyperparams, metadata,
output_folder, verbose, queue):
signal.signal(signal.SIGTERM, lambda signum, frame: signal_handler(queue, signum))
hide_logs(verbose) # Hide logs here too, since multiprocessing has some issues with loggers

builder = BaseBuilder(metadata, automl_hyperparams)
Expand Down

0 comments on commit 66dea64

Please sign in to comment.