本文整理匯總了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)
示例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)
示例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")
示例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)
示例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)
示例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
示例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 == ''
示例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 == ''
示例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
示例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')
示例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)
示例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')
示例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')