Nir Soffer has posted comments on this change. Change subject: signals: Handle signals to non-main threads ......................................................................
Patch Set 7: (5 comments) We can simplify this, removing poll. http://gerrit.ovirt.org/#/c/29392/7/lib/vdsm/sigutils.py File lib/vdsm/sigutils.py: Line 25: import signal Line 26: Line 27: import utils Line 28: Line 29: _signal_poller = None Keep the pipe instead: _wakeup_pipe = None Line 30: Line 31: Line 32: def _get_signal_poller(): Line 33: ''' Line 28: Line 29: _signal_poller = None Line 30: Line 31: Line 32: def _get_signal_poller(): Rename it to init(), or register() The user should call this explicitly, otherwise you loose signals sent early during startup. This is something that the user want to do first thing when the application starts. Also raise if someone call this twice. Line 33: ''' Line 34: This function creates a select.poll object that can be used in the same Line 35: manner as signal.pause(). The poll object returns each time a signal was Line 36: received by the process. Line 40: Line 41: global _signal_poller Line 42: Line 43: if _signal_poller is None: Line 44: read_fd, write_fd = os.pipe() _wakeup_pipe = os.pipe() ? Line 45: Line 46: # The write end is going to be written to from a c-level signal Line 47: # handler, so it has to be non-blocking. Line 48: utils.set_non_blocking(write_fd) Line 47: # handler, so it has to be non-blocking. Line 48: utils.set_non_blocking(write_fd) Line 49: Line 50: # Set the read pipe end to non-blocking too, just in case. Line 51: utils.set_non_blocking(read_fd) Lets keep this in blocking mode. Line 52: Line 53: # Prevent subproccesses we execute from inheriting the pipes. Line 54: utils.closeOnExec(write_fd) Line 55: utils.closeOnExec(read_fd) Line 87: logging.exception( Line 88: 'Received error while reading from pipe') Line 89: except select.error as e: Line 90: if e[0] != errno.EINTR: Line 91: logging.exception('Received error while waiting for signal') Since we don't care about the timeout (nobody ask for timeout), we can replace this with: while True: try: os.read(_wakeup_pipe[0], 128) except OSError as e: if e.errno != errno.EINTR: logging.exception("Error reading from wakeup pipe") else: return # Got a signal -- To view, visit http://gerrit.ovirt.org/29392 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: comment Gerrit-Change-Id: I5dbcd00cec22ef12f2b6253b016dcbd0aa889583 Gerrit-PatchSet: 7 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Dima Kuznetsov <[email protected]> Gerrit-Reviewer: Dan Kenigsberg <[email protected]> Gerrit-Reviewer: Dima Kuznetsov <[email protected]> Gerrit-Reviewer: Nir Soffer <[email protected]> Gerrit-Reviewer: Saggi Mizrahi <[email protected]> Gerrit-Reviewer: Yaniv Bronhaim <[email protected]> Gerrit-Reviewer: [email protected] Gerrit-Reviewer: oVirt Jenkins CI Server Gerrit-HasComments: Yes _______________________________________________ vdsm-patches mailing list [email protected] https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
