#NEWLINE# def test_unresponsive_stop( pyscript ) : #NEWLINE# #INDENT# script = pyscript ( "\n        import signal\n        import sys\n        import time\n        from daemonocle import Daemon\n\n        def worker():\n            def handle_sigterm(*args, **kwargs):\n                time.sleep(10)\n\n            signal.signal(signal.SIGTERM, handle_sigterm)\n            time.sleep(10)\n\n        daemon = Daemon(worker=worker, prog='foo', pidfile='foo.pid',\n                        stop_timeout=1)\n        daemon.do_action(sys.argv[1])\n    " ) #NEWLINE# pidfile = os . path . realpath ( os . path . join ( script . dirname , 'foo.pid' ) ) #NEWLINE# script . run ( 'start' ) #NEWLINE# with open ( pidfile , 'rb' ) as f : #NEWLINE# #INDENT# pid = int ( f . read ( ) ) #NEWLINE# #UNINDENT# result = script . run ( 'stop' ) #NEWLINE# assert ( result . returncode == 1 ) #NEWLINE# assert ( result . stdout == b'Stopping foo ... FAILED\n' ) #NEWLINE# assert ( result . stderr == 'ERROR: Timed out while waiting for process (PID {pid}) to terminate\n' . format ( pid = pid ) . encode ( 'utf-8' ) ) #NEWLINE# assert psutil . pid_exists ( pid ) #NEWLINE# os . kill ( pid , signal . SIGKILL ) #NEWLINE# try : #NEWLINE# #INDENT# proc = psutil . Process ( pid ) #NEWLINE# #UNINDENT# except psutil . NoSuchProcess : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# proc . wait ( timeout = 1 )