async def _ultimate_termination( *, settings: configuration.OperatorSettings, stop_flag: Optional[primitives.Flag], ) -> None: """ Ensure that SIGKILL is sent regardless of the operator's stopping routines. Try to be gentle and kill only the thread with the operator, not the whole process or a process group. If this is the main thread (as in most cases), this would imply the process termination too. Intentional stopping via a stop-flag is ignored. """ # Sleep forever, or until cancelled, which happens when the operator begins its shutdown. try: await asyncio.Event().wait() except asyncio.CancelledError: if not primitives.check_flag(stop_flag): if settings.process.ultimate_exiting_timeout is not None: loop = asyncio.get_running_loop() loop.call_later(settings.process.ultimate_exiting_timeout, signal.pthread_kill, threading.get_ident(), signal.SIGKILL)
async def test_checking_of_concurrent_future_when_unset(): future = concurrent.futures.Future() result = check_flag(future) assert result is False
async def test_checking_of_concurrent_future_when_set(): future = concurrent.futures.Future() future.set_result(None) result = check_flag(future) assert result is True
async def test_checking_of_threading_event_when_unset(): event = threading.Event() event.clear() result = check_flag(event) assert result is False
async def test_checking_of_threading_event_when_set(): event = threading.Event() event.set() result = check_flag(event) assert result is True
async def test_checking_of_asyncio_future_when_empty(): future = asyncio.Future() result = check_flag(future) assert result is False
async def test_checking_of_asyncio_future_when_set(): future = asyncio.Future() future.set_result(None) result = check_flag(future) assert result is True
async def test_checking_of_asyncio_event_when_unset(): event = asyncio.Event() event.clear() result = check_flag(event) assert result is False
async def test_checking_of_asyncio_event_when_raised(): event = asyncio.Event() event.set() result = check_flag(event) assert result is True
async def test_checking_of_none_is_none(): result = check_flag(None) assert result is None
async def test_checking_of_unsupported_raises_an_error(): with pytest.raises(TypeError): check_flag(object())