Changeset 844


Ignore:
Timestamp:
11/23/15 07:32:25 (6 months ago)
Author:
mmckerns
Message:

check if handler enabled before using signal (so solver works in ThreadPool?)

Location:
mystic
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • mystic/examples3/test_searcher.py

    r842 r844  
    1010#   start = time.time() 
    1111    # if available, use a multiprocessing worker pool 
    12     try: #NOTE: ThreadPool and ParallelPool fail 
     12    try: #NOTE: ParallelPool fails 
    1313        from pathos.helpers import freeze_support 
    1414        freeze_support() 
  • mystic/mystic/abstract_solver.py

    r843 r844  
    824824 
    825825        # activate signal handler 
     826       #import threading as thread 
     827       #mainthread = isinstance(thread.current_thread(), thread._MainThread) 
     828       #if mainthread: #XXX: if not mainthread, signal will raise ValueError 
    826829        import signal 
    827         if self._handle_sigint: signal.signal(signal.SIGINT,self.signal_handler) 
     830        if self._handle_sigint: 
     831            signal.signal(signal.SIGINT,self.signal_handler) 
    828832 
    829833        # register: cost, termination, ExtraArgs 
     
    837841 
    838842        # restore default handler for signal interrupts 
    839         signal.signal(signal.SIGINT,signal.default_int_handler) 
     843        if self._handle_sigint: 
     844            signal.signal(signal.SIGINT,signal.default_int_handler) 
    840845        return 
    841846 
  • mystic/mystic/ensemble.py

    r793 r844  
    106106 
    107107        # activate signal_handler 
     108       #import threading as thread 
     109       #mainthread = isinstance(thread.current_thread(), thread._MainThread) 
     110       #if mainthread: #XXX: if not mainthread, signal will raise ValueError 
    108111        import signal 
    109         if self._handle_sigint: signal.signal(signal.SIGINT,self.signal_handler) 
     112        if self._handle_sigint: 
     113            signal.signal(signal.SIGINT,self.signal_handler) 
    110114 
    111115        # register termination function 
     
    228232 
    229233        # restore default handler for signal interrupts 
    230         signal.signal(signal.SIGINT,signal.default_int_handler) 
     234        if self._handle_sigint: 
     235            signal.signal(signal.SIGINT,signal.default_int_handler) 
    231236 
    232237        # log any termination messages 
     
    303308 
    304309        # activate signal_handler 
     310       #import threading as thread 
     311       #mainthread = isinstance(thread.current_thread(), thread._MainThread) 
     312       #if mainthread: #XXX: if not mainthread, signal will raise ValueError 
    305313        import signal 
    306         if self._handle_sigint: signal.signal(signal.SIGINT,self.signal_handler) 
     314        if self._handle_sigint: 
     315            signal.signal(signal.SIGINT,self.signal_handler) 
    307316 
    308317        # register termination function 
     
    418427 
    419428        # restore default handler for signal interrupts 
    420         signal.signal(signal.SIGINT,signal.default_int_handler) 
     429        if self._handle_sigint: 
     430            signal.signal(signal.SIGINT,signal.default_int_handler) 
    421431 
    422432        # log any termination messages 
Note: See TracChangeset for help on using the changeset viewer.