Skip to content

Change PubSub::listen() exist on both SIGTERM and SIGINT and add Python signal handler support.#626

Closed
liuh-80 wants to merge 3 commits intosonic-net:masterfrom
liuh-80:dev/liuh/add-sig-term
Closed

Change PubSub::listen() exist on both SIGTERM and SIGINT and add Python signal handler support.#626
liuh-80 wants to merge 3 commits intosonic-net:masterfrom
liuh-80:dev/liuh/add-sig-term

Conversation

@liuh-80
Copy link
Contributor

@liuh-80 liuh-80 commented Jun 1, 2022

Why I did it

Fix hostcfgd can't terminate by SIGTERM and SIGINT issue:
https://github.com/Azure/sonic-swss-common/issues/603

PubSub::listen() need exist when receive SIGTERM and SIGINT.

How I did it

Change code to exist when receive SIGTERM and SIGINT.
Add python signal handler support.

How to verify it

  1. manually test.
  2. Pass all test case.

Which release branch to backport (provide reason below if selected)

  • 201811
  • 201911
  • 202006
  • 202012
  • 202106
  • 202111

Description for the changelog

Link to config_db schema for YANG module changes

A picture of a cute animal (not mandatory but encouraged)

@liuh-80
Copy link
Contributor Author

liuh-80 commented Jun 1, 2022

Will improve code coverage by add new UT and update later.

@liuh-80 liuh-80 changed the title Change PubSub::listen() exist on both SIGTERM and SIGINT Change PubSub::listen() exist on both SIGTERM and SIGINT and add Python signal handler support. Jun 6, 2022
@liuh-80
Copy link
Contributor Author

liuh-80 commented Jun 6, 2022

Example code:

import signal
import os
import time
import threading

from swsscommon.signal import RegisterSignal

def dummy_signal_handler(signum, frame):
print("SIGNAL {} happen".format(signum))

RegisterSignal(signal.SIGINT, dummy_signal_handler) <== register python signal handler to swss-common

from swsscommon.swsscommon import ConfigDBConnector

conn = ConfigDBConnector()
conn.connect()
conn.subscribe('A', lambda a: None)
conn.listen()
^CSIGNAL 2 happen

@liuh-80
Copy link
Contributor Author

liuh-80 commented Jun 10, 2022

Code change in this PR need test with another PR for buildimage repo not break by this PR: sonic-net/sonic-buildimage#11100

@liuh-80
Copy link
Contributor Author

liuh-80 commented Jun 16, 2022

Closed because steppan's PR have a better solution: https://github.com/Azure/sonic-swss-common/pull/624/files

@liuh-80 liuh-80 closed this Jun 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant