Changeset 267b8d


Ignore:
Timestamp:
Jul 2, 2012, 8:32:05 AM (13 years ago)
Author:
Frederik Heber <heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
af9b9ff
Parents:
d9373b
git-author:
Frederik Heber <heber@…> (05/03/12 11:14:23)
git-committer:
Frederik Heber <heber@…> (07/02/12 08:32:05)
Message:

Server now also intercepts sigint and shuts down gracefully.

  • new FragmentScheduler::shutdown() function is bound and given as signal handler.
  • on signal we first remove all workers and only shutdown and close sockets when there are no workers.
  • note that we do not release the signalhandler after first received signal but after a given number as two ctrl-c are required to shut down server having poolworkers.
Location:
src/Fragmentation/Automation
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/Fragmentation/Automation/FragmentScheduler.cpp

    rd9373b r267b8d  
    562562}
    563563
     564/** Function to shutdown server properly, e.g. for use as signal handler.
     565 *
     566 * @param sig signal number
     567 */
     568void FragmentScheduler::shutdown(int sig)
     569{
     570  LOG(0, "STATUS: Shutting down due to signal " << sig << ".");
     571
     572  if (!pool.presentIdleWorkers() && !pool.hasBusyWorkers()) {
     573    shutdown();
     574  } else {
     575    removeAllWorkers();
     576  }
     577}
     578
    564579/** Helper function to shutdown the server properly.
    565580 *
  • src/Fragmentation/Automation/FragmentScheduler.hpp

    rd9373b r267b8d  
    4949  ~FragmentScheduler();
    5050
     51  void shutdown(int sig);
    5152private:
    5253  void sendJobToWorker(const WorkerAddress &address, FragmentJob::ptr &job);
     
    6061  void recieveNotification(Observable *publisher, Notification_ptr notification);
    6162  void subjectKilled(Observable *publisher);
    62 
    6363
    6464  class WorkerListener_t : public Listener
  • src/Fragmentation/Automation/Server.cpp

    rd9373b r267b8d  
    2929#include <boost/program_options.hpp>
    3030#include <iostream>
     31#include <signal.h>
    3132
    3233#include "atexit.hpp"
     
    3536#include "FragmentScheduler.hpp"
    3637
     38
     39//!> global shutdown function
     40boost::function<void (int)> shutdownfunction;
     41//!> global signal vector for later releasing
     42std::vector<size_t> signals;
     43//!> counter for the number of received signals
     44size_t NoSignalsReceived = 0;
     45//!> maximum number of received signals after which the handlers are released
     46const size_t MAX_NOSIGNALSRECEIVED = 3;
     47
     48void signalhandler(int sig)
     49{
     50  // increment received signal counter
     51  ++NoSignalsReceived;
     52
     53  // shutdown if we have handler
     54  if (shutdownfunction)
     55    shutdownfunction(sig);
     56
     57  if (NoSignalsReceived >= MAX_NOSIGNALSRECEIVED) {
     58    // release signal hook again
     59    for (std::vector<size_t>::const_iterator iter = signals.begin();
     60        iter != signals.end(); ++iter)
     61      signal(*iter, NULL);
     62  }
     63}
    3764
    3865int main(int argc, char* argv[])
     
    4774      ("help,h", "produce help message")
    4875      ("verbosity,v", boost::program_options::value<size_t>(), "set verbosity level")
     76      ("signal", boost::program_options::value< std::vector<size_t> >(), "set signal to catch (can be given multiple times)")
    4977      ("workerport", boost::program_options::value< unsigned short >(), "listen on this port for connecting workers")
    5078      ("controllerport", boost::program_options::value< unsigned short >(), "listen on this port for connecting controller")
     
    101129    boost::asio::io_service io_service;
    102130    FragmentScheduler Server(io_service, workerport, controllerport);
     131
     132    // catch ctrl-c and shutdown worker properly
     133    shutdownfunction = boost::bind(&FragmentScheduler::shutdown, boost::ref(Server), _1);
     134    if (vm.count("signal")) {
     135      signals =  vm["signal"].as< std::vector<size_t> >();
     136      for (std::vector<size_t>::const_iterator iter = signals.begin();
     137          iter != signals.end(); ++iter) {
     138        LOG(0, "STATUS: Catching signal " << *iter << " via signal handler.");
     139        signal(*iter, &signalhandler);
     140      }
     141    } else {
     142      LOG(0, "STATUS: No signals are caught.");
     143    }
     144
    103145    {
    104146      Info info("io_service");
  • src/Fragmentation/Automation/poolworker.cpp

    rd9373b r267b8d  
    4242//!> global signal vector for later releasing
    4343std::vector<size_t> signals;
     44//!> counter for the number of received signals
     45size_t NoSignalsReceived = 0;
     46//!> maximum number of received signals after which the handlers are released
     47const size_t MAX_NOSIGNALSRECEIVED = 3;
    4448
    4549void signalhandler(int sig)
    4650{
     51  // increment received signal counter
     52  ++NoSignalsReceived;
     53
    4754  // shutdown if we have handler
    4855  if (shutdownfunction)
    4956    shutdownfunction(sig);
    5057
    51   // release signal hook again
    52   for (std::vector<size_t>::const_iterator iter = signals.begin();
    53       iter != signals.end(); ++iter)
    54     signal(*iter, NULL);
     58  if (NoSignalsReceived >= MAX_NOSIGNALSRECEIVED) {
     59    // release signal hook again
     60    for (std::vector<size_t>::const_iterator iter = signals.begin();
     61        iter != signals.end(); ++iter)
     62      signal(*iter, NULL);
     63  }
    5564}
    5665
Note: See TracChangeset for help on using the changeset viewer.