当前位置: 首页>>代码示例>>Python>>正文


Python signal.SIGINT属性代码示例

本文整理汇总了Python中signal.SIGINT属性的典型用法代码示例。如果您正苦于以下问题:Python signal.SIGINT属性的具体用法?Python signal.SIGINT怎么用?Python signal.SIGINT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在signal的用法示例。


在下文中一共展示了signal.SIGINT属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testInterruptCaught

# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGINT [as 别名]
def testInterruptCaught(self):
        default_handler = signal.getsignal(signal.SIGINT)

        result = unittest.TestResult()
        unittest.installHandler()
        unittest.registerResult(result)

        self.assertNotEqual(signal.getsignal(signal.SIGINT), default_handler)

        def test(result):
            pid = os.getpid()
            os.kill(pid, signal.SIGINT)
            result.breakCaught = True
            self.assertTrue(result.shouldStop)

        try:
            test(result)
        except KeyboardInterrupt:
            self.fail("KeyboardInterrupt not handled")
        self.assertTrue(result.breakCaught) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:22,代码来源:test_break.py

示例2: testSecondInterrupt

# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGINT [as 别名]
def testSecondInterrupt(self):
        result = unittest.TestResult()
        unittest.installHandler()
        unittest.registerResult(result)

        def test(result):
            pid = os.getpid()
            os.kill(pid, signal.SIGINT)
            result.breakCaught = True
            self.assertTrue(result.shouldStop)
            os.kill(pid, signal.SIGINT)
            self.fail("Second KeyboardInterrupt not raised")

        try:
            test(result)
        except KeyboardInterrupt:
            pass
        else:
            self.fail("Second KeyboardInterrupt not raised")
        self.assertTrue(result.breakCaught) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:22,代码来源:test_break.py

示例3: testHandlerReplacedButCalled

# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGINT [as 别名]
def testHandlerReplacedButCalled(self):
        # If our handler has been replaced (is no longer installed) but is
        # called by the *new* handler, then it isn't safe to delay the
        # SIGINT and we should immediately delegate to the default handler
        unittest.installHandler()

        handler = signal.getsignal(signal.SIGINT)
        def new_handler(frame, signum):
            handler(frame, signum)
        signal.signal(signal.SIGINT, new_handler)

        try:
            pid = os.getpid()
            os.kill(pid, signal.SIGINT)
        except KeyboardInterrupt:
            pass
        else:
            self.fail("replaced but delegated handler doesn't raise interrupt") 
开发者ID:war-and-code,项目名称:jawfish,代码行数:20,代码来源:test_break.py

示例4: testRemoveResult

# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGINT [as 别名]
def testRemoveResult(self):
        result = unittest.TestResult()
        unittest.registerResult(result)

        unittest.installHandler()
        self.assertTrue(unittest.removeResult(result))

        # Should this raise an error instead?
        self.assertFalse(unittest.removeResult(unittest.TestResult()))

        try:
            pid = os.getpid()
            os.kill(pid, signal.SIGINT)
        except KeyboardInterrupt:
            pass

        self.assertFalse(result.shouldStop) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:19,代码来源:test_break.py

示例5: exitus

# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGINT [as 别名]
def exitus(self, status=0, message="end"):
        """
        Called when the program should be exit

        @param status:
            the exit status program returns to callert
        @param message:
            the message logged before exit
        """
        # pylint: disable=global-statement
        global SCRIPTNAME
        global SCRIPTPID
        global VER
        # pylint: enable=global-statement
        if message is not None:
            log(1, message)
        log(0, '{}[{}] v{} end'.format(SCRIPTNAME, SCRIPTPID, VER))
        if status in (signal.SIGINT, signal.SIGTERM):
            status = 0
        sys.exit(status) 
开发者ID:curzon01,项目名称:mqtt2sql,代码行数:22,代码来源:mqtt2sql.py

示例6: test_dummy_service

# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGINT [as 别名]
def test_dummy_service(monkeypatch: Any, capsys: Any, loop: Any) -> None:
    services, future = start_service('tests/services/dummy_service.py', monkeypatch)

    assert services is not None
    assert len(services) == 1
    instance = services.get('test_dummy')
    assert instance is not None
    assert instance.start is True
    assert instance.started is True
    assert instance.stop is False

    assert tomodachi.get_instance() == instance
    assert tomodachi.get_service() == instance
    assert tomodachi.get_service('test_dummy') == instance
    assert tomodachi.get_service('test_dummy_nonexistant') is None

    async def _async_kill():
        os.kill(os.getpid(), signal.SIGINT)

    loop.create_task(_async_kill())
    loop.run_until_complete(future)

    assert instance.stop is True 
开发者ID:kalaspuff,项目名称:tomodachi,代码行数:25,代码来源:test_dummy_service.py

示例7: test_publish_invalid_credentials

# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGINT [as 别名]
def test_publish_invalid_credentials(monkeypatch: Any, capsys: Any, loop: Any) -> None:
    services, future = start_service('tests/services/dummy_service.py', monkeypatch)

    instance = services.get('test_dummy')

    with pytest.raises(AWSSNSSQSException):
        loop.run_until_complete(AWSSNSSQSTransport.publish(instance, 'data', 'test-topic', wait=True))

    async def _async_kill():
        os.kill(os.getpid(), signal.SIGINT)

    loop.create_task(_async_kill())
    loop.run_until_complete(future)

    if not future.done():
        future.set_result(None)

    out, err = capsys.readouterr()
    assert 'The security token included in the request is invalid' in err
    assert out == '' 
开发者ID:kalaspuff,项目名称:tomodachi,代码行数:22,代码来源:test_aws_sns_sqs_transport.py

示例8: test_publish_invalid_credentials

# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGINT [as 别名]
def test_publish_invalid_credentials(monkeypatch: Any, capsys: Any, loop: Any) -> None:
    services, future = start_service('tests/services/dummy_service.py', monkeypatch)

    instance = services.get('test_dummy')

    with pytest.raises(AmqpException):
        loop.run_until_complete(AmqpTransport.publish(instance, 'data', 'test.topic', wait=True))

    async def _async_kill():
        os.kill(os.getpid(), signal.SIGINT)

    loop.create_task(_async_kill())
    loop.run_until_complete(future)

    out, err = capsys.readouterr()
    assert 'Unable to connect [amqp] to 127.0.0.1:54321' in err
    assert out == '' 
开发者ID:kalaspuff,项目名称:tomodachi,代码行数:19,代码来源:test_amqp_transport.py

示例9: test_relative_import_service

# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGINT [as 别名]
def test_relative_import_service(monkeypatch: Any, capsys: Any, loop: Any) -> None:
    services, future = start_service('tests/services/relative_service.py', monkeypatch)

    assert services is not None
    assert len(services) == 1
    instance = services.get('test_relative')
    assert instance is not None
    assert instance.start is True
    assert instance.started is True
    assert instance.stop is False

    async def _async_kill():
        os.kill(os.getpid(), signal.SIGINT)

    loop.create_task(_async_kill())
    loop.run_until_complete(future)

    assert instance.stop is True 
开发者ID:kalaspuff,项目名称:tomodachi,代码行数:20,代码来源:test_relative_imports.py

示例10: _started_service

# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGINT [as 别名]
def _started_service(self) -> None:
        async def publish(data: Any, routing_key: str) -> None:
            await amqp_publish(self, data, routing_key=routing_key, wait=False)

        async def _async() -> None:
            async def sleep_and_kill() -> None:
                await asyncio.sleep(10.0)
                if not self.closer.done():
                    self.closer.set_result(None)

            task = asyncio.ensure_future(sleep_and_kill())
            await self.closer
            if not task.done():
                task.cancel()
            os.kill(os.getpid(), signal.SIGINT)
        asyncio.ensure_future(_async())

        self.data_uuid = str(uuid.uuid4())
        await publish(self.data_uuid, 'test.raw.topic') 
开发者ID:kalaspuff,项目名称:tomodachi,代码行数:21,代码来源:amqp_service_with_credentials_without_protocol.py

示例11: _started_service

# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGINT [as 别名]
def _started_service(self) -> None:
        async def publish(data: Any, topic: str) -> None:
            await aws_sns_sqs_publish(self, data, topic=topic, wait=False, message_protocol=CustomProtocol)

        async def _async() -> None:
            async def sleep_and_kill() -> None:
                await asyncio.sleep(10.0)
                if not self.closer.done():
                    self.closer.set_result(None)

            task = asyncio.ensure_future(sleep_and_kill())
            await self.closer
            if not task.done():
                task.cancel()
            os.kill(os.getpid(), signal.SIGINT)
        asyncio.ensure_future(_async())

        self.data_uuid = str(uuid.uuid4())
        for _ in range(30):
            if self.test_topic_data_received:
                break
            await publish(self.data_uuid, 'test-custom-topic')
            await asyncio.sleep(0.1) 
开发者ID:kalaspuff,项目名称:tomodachi,代码行数:25,代码来源:aws_sns_sqs_service_with_credentials_with_custom_protocol.py

示例12: _started_service

# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGINT [as 别名]
def _started_service(self) -> None:
        async def publish(data: Any, topic: str) -> None:
            await aws_sns_sqs_publish(self, data, topic=topic, wait=False)

        async def _async() -> None:
            async def sleep_and_kill() -> None:
                await asyncio.sleep(10.0)
                if not self.closer.done():
                    self.closer.set_result(None)

            task = asyncio.ensure_future(sleep_and_kill())
            await self.closer
            if not task.done():
                task.cancel()
            os.kill(os.getpid(), signal.SIGINT)
        asyncio.ensure_future(_async())

        self.data_uuid = str(uuid.uuid4())
        await publish(self.data_uuid, 'test-topic-unique')
        for _ in range(30):
            if self.test_topic_data_received:
                break
            await publish(self.data_uuid, 'test-topic')
            await asyncio.sleep(0.1) 
开发者ID:kalaspuff,项目名称:tomodachi,代码行数:26,代码来源:aws_sns_sqs_service_with_credentials.py

示例13: _started_service

# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGINT [as 别名]
def _started_service(self) -> None:
        async def publish(data: Any, routing_key: str) -> None:
            await amqp_publish(self, data, routing_key=routing_key, wait=False, message_protocol=CustomProtocol)

        async def _async() -> None:
            async def sleep_and_kill() -> None:
                await asyncio.sleep(10.0)
                if not self.closer.done():
                    self.closer.set_result(None)

            task = asyncio.ensure_future(sleep_and_kill())
            await self.closer
            if not task.done():
                task.cancel()
            os.kill(os.getpid(), signal.SIGINT)
        asyncio.ensure_future(_async())

        self.data_uuid = str(uuid.uuid4())
        await publish(self.data_uuid, 'test.custom.topic') 
开发者ID:kalaspuff,项目名称:tomodachi,代码行数:21,代码来源:amqp_service_with_credentials_with_custom_protocol.py

示例14: _started_service

# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGINT [as 别名]
def _started_service(self) -> None:
        async def publish(data: Any, topic: str) -> None:
            await aws_sns_sqs_publish(self, data, topic=topic, wait=False)

        async def _async() -> None:
            async def sleep_and_kill() -> None:
                await asyncio.sleep(10.0)
                if not self.closer.done():
                    self.closer.set_result(None)

            task = asyncio.ensure_future(sleep_and_kill())
            await self.closer
            if not task.done():
                task.cancel()
            os.kill(os.getpid(), signal.SIGINT)
        asyncio.ensure_future(_async())

        self.data_uuid = str(uuid.uuid4())
        for _ in range(30):
            if self.test_topic_data_received:
                break
            await publish(self.data_uuid, 'test-raw-topic')
            await asyncio.sleep(0.1) 
开发者ID:kalaspuff,项目名称:tomodachi,代码行数:25,代码来源:aws_sns_sqs_service_with_credentials_without_protocol.py

示例15: _started_service

# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGINT [as 别名]
def _started_service(self) -> None:
        async def publish(data: Any, routing_key: str) -> None:
            await amqp_publish(self, data, routing_key=routing_key, wait=True)

        async def _async() -> None:
            async def sleep_and_kill() -> None:
                await asyncio.sleep(10.0)
                if not self.closer.done():
                    self.closer.set_result(None)

            task = asyncio.ensure_future(sleep_and_kill())
            await self.closer
            if not task.done():
                task.cancel()
            os.kill(os.getpid(), signal.SIGINT)
        asyncio.ensure_future(_async())

        self.data_uuid = str(uuid.uuid4())
        await publish(self.data_uuid, 'test.topic') 
开发者ID:kalaspuff,项目名称:tomodachi,代码行数:21,代码来源:amqp_service_with_credentials.py


注:本文中的signal.SIGINT属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。