Python select.POLLNVAL Examples

The following are 30 code examples of select.POLLNVAL(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module select , or try the search function .
Example #1
Source File: pprocess.py    From Aegean with Academic Free License v3.0 6 votes vote down vote up
def _ensure_communication(self, timeout=None):

        "Ensure that sending and receiving are possible."

        while 1:
            self._ensure_pipes()
            fileno = self.write_pipe.fileno()
            fds = self.poller.poll(timeout)
            for fd, status in fds:
                if fd != fileno:
                    continue
                if status & (select.POLLHUP | select.POLLNVAL | select.POLLERR):

                    # Broken connection: discard it and start all over again.

                    self._reset_pipes()
                    break
            else:
                return 
Example #2
Source File: asyncore.py    From android_universal with MIT License 6 votes vote down vote up
def readwrite(obj, flags):
    try:
        if flags & select.POLLIN:
            obj.handle_read_event()
        if flags & select.POLLOUT:
            obj.handle_write_event()
        if flags & select.POLLPRI:
            obj.handle_expt_event()
        if flags & (select.POLLHUP | select.POLLERR | select.POLLNVAL):
            obj.handle_close()
    except OSError as e:
        if e.args[0] not in _DISCONNECTED:
            obj.handle_error()
        else:
            obj.handle_close()
    except _reraised_exceptions:
        raise
    except:
        obj.handle_error() 
Example #3
Source File: poll.py    From multibootusb with GNU General Public License v2.0 6 votes vote down vote up
def _parse_events(self, events):
        """Parse ``events``.

        ``events`` is a list of events as returned by
        :meth:`select.poll.poll()`.

        Yield all parsed events.

        """
        for fd, event_mask in events:
            if self._has_event(event_mask, select.POLLNVAL):
                raise IOError('File descriptor not open: {0!r}'.format(fd))
            elif self._has_event(event_mask, select.POLLERR):
                raise IOError('Error while polling fd: {0!r}'.format(fd))

            if self._has_event(event_mask, select.POLLIN):
                yield fd, 'r'
            if self._has_event(event_mask, select.POLLOUT):
                yield fd, 'w'
            if self._has_event(event_mask, select.POLLHUP):
                yield fd, 'h' 
Example #4
Source File: CLIManager.py    From rtp_cluster with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def run(self):
        #print(self.run, 'enter')
        while True:
            #print(self.run, 'cycle')
            pollret = dict(self.pollobj.poll()).get(self.fileno, 0)
            if pollret & POLLNVAL != 0:
                break
            if pollret & POLLIN == 0:
                continue
            try:
                clientsock, addr = self.clicm.serversock.accept()
            except Exception as why:
                if isinstance(why, socket.error):
                    if why.errno == ECONNABORTED:
                        continue
                    elif why.errno == EBADF:
                        break
                    else:
                        raise
                dump_exception('CLIConnectionManager: unhandled exception when accepting incoming connection')
                break
            #print(self.run, 'handle_accept')
            ED2.callFromThread(self.clicm.handle_accept, clientsock, addr)
        self.clicm = None
        #print(self.run, 'exit') 
Example #5
Source File: serialposix.py    From Jandroid with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def read(self, size=1):
        """Read size bytes from the serial port. If a timeout is set it may
           return less characters as requested. With no timeout it will block
           until the requested number of bytes is read."""
        if self.fd is None: raise portNotOpenError
        read = bytearray()
        poll = select.poll()
        poll.register(self.fd, select.POLLIN|select.POLLERR|select.POLLHUP|select.POLLNVAL)
        if size > 0:
            while len(read) < size:
                # print "\tread(): size",size, "have", len(read)    #debug
                # wait until device becomes ready to read (or something fails)
                for fd, event in poll.poll(self._timeout*1000):
                    if event & (select.POLLERR|select.POLLHUP|select.POLLNVAL):
                        raise SerialException('device reports error (poll)')
                    #  we don't care if it is select.POLLIN or timeout, that's
                    #  handled below
                buf = os.read(self.fd, size - len(read))
                read.extend(buf)
                if ((self._timeout is not None and self._timeout >= 0) or 
                    (self._interCharTimeout is not None and self._interCharTimeout > 0)) and not buf:
                    break   # early abort on timeout
        return bytes(read) 
Example #6
Source File: CLIManager.py    From b2bua with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def run(self):
        #print(self.run, 'enter')
        while True:
            #print(self.run, 'cycle')
            pollret = dict(self.pollobj.poll()).get(self.fileno, 0)
            if pollret & POLLNVAL != 0:
                break
            if pollret & POLLIN == 0:
                continue
            try:
                clientsock, addr = self.clicm.serversock.accept()
            except Exception as why:
                if isinstance(why, socket.error):
                    if why.errno == ECONNABORTED:
                        continue
                    elif why.errno == EBADF:
                        break
                    else:
                        raise
                dump_exception('CLIConnectionManager: unhandled exception when accepting incoming connection')
                break
            #print(self.run, 'handle_accept')
            ED2.callFromThread(self.clicm.handle_accept, clientsock, addr)
        self.clicm = None
        #print(self.run, 'exit') 
Example #7
Source File: serialposix.py    From Jandroid with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def read(self, size=1):
        """Read size bytes from the serial port. If a timeout is set it may
           return less characters as requested. With no timeout it will block
           until the requested number of bytes is read."""
        if self.fd is None: raise portNotOpenError
        read = bytearray()
        poll = select.poll()
        poll.register(self.fd, select.POLLIN|select.POLLERR|select.POLLHUP|select.POLLNVAL)
        if size > 0:
            while len(read) < size:
                # print "\tread(): size",size, "have", len(read)    #debug
                # wait until device becomes ready to read (or something fails)
                for fd, event in poll.poll(self._timeout*1000):
                    if event & (select.POLLERR|select.POLLHUP|select.POLLNVAL):
                        raise SerialException('device reports error (poll)')
                    #  we don't care if it is select.POLLIN or timeout, that's
                    #  handled below
                buf = os.read(self.fd, size - len(read))
                read.extend(buf)
                if ((self._timeout is not None and self._timeout >= 0) or 
                    (self._interCharTimeout is not None and self._interCharTimeout > 0)) and not buf:
                    break   # early abort on timeout
        return bytes(read) 
Example #8
Source File: serialposix.py    From Jandroid with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def read(self, size=1):
        """Read size bytes from the serial port. If a timeout is set it may
           return less characters as requested. With no timeout it will block
           until the requested number of bytes is read."""
        if self.fd is None: raise portNotOpenError
        read = bytearray()
        poll = select.poll()
        poll.register(self.fd, select.POLLIN|select.POLLERR|select.POLLHUP|select.POLLNVAL)
        if size > 0:
            while len(read) < size:
                # print "\tread(): size",size, "have", len(read)    #debug
                # wait until device becomes ready to read (or something fails)
                for fd, event in poll.poll(self._timeout*1000):
                    if event & (select.POLLERR|select.POLLHUP|select.POLLNVAL):
                        raise SerialException('device reports error (poll)')
                    #  we don't care if it is select.POLLIN or timeout, that's
                    #  handled below
                buf = os.read(self.fd, size - len(read))
                read.extend(buf)
                if ((self._timeout is not None and self._timeout >= 0) or 
                    (self._interCharTimeout is not None and self._interCharTimeout > 0)) and not buf:
                    break   # early abort on timeout
        return bytes(read) 
Example #9
Source File: asyncore.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 6 votes vote down vote up
def readwrite(obj, flags):
    try:
        if flags & select.POLLIN:
            obj.handle_read_event()
        if flags & select.POLLOUT:
            obj.handle_write_event()
        if flags & select.POLLPRI:
            obj.handle_expt_event()
        if flags & (select.POLLHUP | select.POLLERR | select.POLLNVAL):
            obj.handle_close()
    except OSError as e:
        if e.args[0] not in _DISCONNECTED:
            obj.handle_error()
        else:
            obj.handle_close()
    except _reraised_exceptions:
        raise
    except:
        obj.handle_error() 
Example #10
Source File: asyncore.py    From Fluid-Designer with GNU General Public License v3.0 6 votes vote down vote up
def readwrite(obj, flags):
    try:
        if flags & select.POLLIN:
            obj.handle_read_event()
        if flags & select.POLLOUT:
            obj.handle_write_event()
        if flags & select.POLLPRI:
            obj.handle_expt_event()
        if flags & (select.POLLHUP | select.POLLERR | select.POLLNVAL):
            obj.handle_close()
    except OSError as e:
        if e.args[0] not in _DISCONNECTED:
            obj.handle_error()
        else:
            obj.handle_close()
    except _reraised_exceptions:
        raise
    except:
        obj.handle_error() 
Example #11
Source File: compat.py    From NoobSec-Toolkit with GNU General Public License v2.0 6 votes vote down vote up
def poll(self, timeout = None):
            events = self._poll.poll(timeout)
            processed = []
            for fd, evt in events:
                mask = ""
                if evt & (select_module.POLLIN | select_module.POLLPRI):
                    mask += "r"
                if evt & select_module.POLLOUT:
                    mask += "w"
                if evt & select_module.POLLERR:
                    mask += "e"
                if evt & select_module.POLLHUP:
                    mask += "h"
                if evt & select_module.POLLNVAL:
                    mask += "n"
                processed.append((fd, mask))
            return processed 
Example #12
Source File: _posix_wait.py    From loky with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def _poll(fds, timeout):
        if timeout is not None:
            timeout = int(timeout * 1000)  # timeout is in milliseconds
        fd_map = {}
        pollster = select.poll()
        for fd in fds:
            pollster.register(fd, select.POLLIN)
            if hasattr(fd, 'fileno'):
                fd_map[fd.fileno()] = fd
            else:
                fd_map[fd] = fd
        ls = []
        for fd, event in pollster.poll(timeout):
            if event & select.POLLNVAL:  # pragma: no cover
                raise ValueError('invalid file descriptor %i' % fd)
            ls.append(fd_map[fd])
        return ls 
Example #13
Source File: compat.py    From NoobSec-Toolkit with GNU General Public License v2.0 6 votes vote down vote up
def poll(self, timeout = None):
            events = self._poll.poll(timeout)
            processed = []
            for fd, evt in events:
                mask = ""
                if evt & (select_module.POLLIN | select_module.POLLPRI):
                    mask += "r"
                if evt & select_module.POLLOUT:
                    mask += "w"
                if evt & select_module.POLLERR:
                    mask += "e"
                if evt & select_module.POLLHUP:
                    mask += "h"
                if evt & select_module.POLLNVAL:
                    mask += "n"
                processed.append((fd, mask))
            return processed 
Example #14
Source File: asyncore.py    From Imogen with MIT License 6 votes vote down vote up
def readwrite(obj, flags):
    try:
        if flags & select.POLLIN:
            obj.handle_read_event()
        if flags & select.POLLOUT:
            obj.handle_write_event()
        if flags & select.POLLPRI:
            obj.handle_expt_event()
        if flags & (select.POLLHUP | select.POLLERR | select.POLLNVAL):
            obj.handle_close()
    except OSError as e:
        if e.args[0] not in _DISCONNECTED:
            obj.handle_error()
        else:
            obj.handle_close()
    except _reraised_exceptions:
        raise
    except:
        obj.handle_error() 
Example #15
Source File: sh.py    From scylla with Apache License 2.0 6 votes vote down vote up
def poll(self, timeout):
            if timeout is not None:
                # convert from seconds to milliseconds
                timeout *= 1000
            changes = self._poll.poll(timeout)
            results = []
            for fd, events in changes:
                f = self._get_file_object(fd)
                if events & (select.POLLIN | select.POLLPRI):
                    results.append((f, POLLER_EVENT_READ))
                elif events & (select.POLLOUT):
                    results.append((f, POLLER_EVENT_WRITE))
                elif events & (select.POLLHUP):
                    results.append((f, POLLER_EVENT_HUP))
                elif events & (select.POLLERR | select.POLLNVAL):
                    results.append((f, POLLER_EVENT_ERROR))
            return results 
Example #16
Source File: asyncore.py    From ironpython3 with Apache License 2.0 6 votes vote down vote up
def readwrite(obj, flags):
    try:
        if flags & select.POLLIN:
            obj.handle_read_event()
        if flags & select.POLLOUT:
            obj.handle_write_event()
        if flags & select.POLLPRI:
            obj.handle_expt_event()
        if flags & (select.POLLHUP | select.POLLERR | select.POLLNVAL):
            obj.handle_close()
    except OSError as e:
        if e.args[0] not in _DISCONNECTED:
            obj.handle_error()
        else:
            obj.handle_close()
    except _reraised_exceptions:
        raise
    except:
        obj.handle_error() 
Example #17
Source File: serialposix.py    From AstroBox with GNU Affero General Public License v3.0 6 votes vote down vote up
def read(self, size=1):
        """Read size bytes from the serial port. If a timeout is set it may
           return less characters as requested. With no timeout it will block
           until the requested number of bytes is read."""
        if self.fd is None: raise portNotOpenError
        read = bytearray()
        poll = select.poll()
        poll.register(self.fd, select.POLLIN|select.POLLERR|select.POLLHUP|select.POLLNVAL)
        if size > 0:
            while len(read) < size:
                # print "\tread(): size",size, "have", len(read)    #debug
                # wait until device becomes ready to read (or something fails)
                for fd, event in poll.poll(self._timeout*1000):
                    if event & (select.POLLERR|select.POLLHUP|select.POLLNVAL):
                        raise SerialException('device reports error (poll)')
                    #  we don't care if it is select.POLLIN or timeout, that's
                    #  handled below
                buf = os.read(self.fd, size - len(read))
                read.extend(buf)
                if ((self._timeout is not None and self._timeout >= 0) or 
                    (self._interCharTimeout is not None and self._interCharTimeout > 0)) and not buf:
                    break   # early abort on timeout
        return bytes(read) 
Example #18
Source File: pprocess.py    From Aegean with Academic Free License v3.0 6 votes vote down vote up
def _ensure_pipes(self):

        "Ensure that the channel is capable of communicating."

        if self.read_pipe is None or self.write_pipe is None:

            # Accept any incoming connections.

            endpoint, address = self.endpoint.accept()
            self.read_pipe = endpoint.makefile("rb", 0)
            self.write_pipe = endpoint.makefile("wb", 0)

            # Monitor the write pipe for error conditions.

            fileno = self.write_pipe.fileno()
            self.poller.register(fileno, select.POLLOUT | select.POLLHUP | select.POLLNVAL | select.POLLERR) 
Example #19
Source File: IOManager.py    From redeem with GNU General Public License v3.0 5 votes vote down vote up
def add_file(self, file, callback):
    logging.debug("IOManager adding file: %s", str(file))

    def add_handler(poller, callbacks):
      poller.register(
          file, select.POLLIN | select.POLLPRI | select.POLLERR | select.POLLHUP | select.POLLNVAL)
      callbacks[file.fileno()] = callback
      logging.debug("IOManager thread added file successfully")
      return True

    self.control_queue.put(add_handler)
    self._wake_io_thread()
    self.control_queue.join() 
Example #20
Source File: asyncore.py    From canape with GNU General Public License v3.0 5 votes vote down vote up
def poll2(timeout=0.0, map=None):
    # Use the poll() support added to the select module in Python 2.0
    if map is None:
        map = socket_map
    if timeout is not None:
        # timeout is in milliseconds
        timeout = int(timeout*1000)
    pollster = select.poll()
    if map:
        for fd, obj in map.items():
            flags = 0
            if obj.readable():
                flags |= select.POLLIN | select.POLLPRI
            if obj.writable():
                flags |= select.POLLOUT
            if flags:
                # Only check for exceptions if object was either readable
                # or writable.
                flags |= select.POLLERR | select.POLLHUP | select.POLLNVAL
                pollster.register(fd, flags)
        try:
            r = pollster.poll(timeout)
        except select.error, err:
            if err.args[0] != EINTR:
                raise
            r = []
        for fd, flags in r:
            obj = map.get(fd)
            if obj is None:
                continue
            readwrite(obj, flags) 
Example #21
Source File: events.py    From libvirt-test-API with GNU General Public License v2.0 5 votes vote down vote up
def events_from_poll(self, events):
        ret = 0
        if events & select.POLLIN:
            ret |= libvirt.VIR_EVENT_HANDLE_READABLE
        if events & select.POLLOUT:
            ret |= libvirt.VIR_EVENT_HANDLE_WRITABLE
        if events & select.POLLNVAL:
            ret |= libvirt.VIR_EVENT_HANDLE_ERROR
        if events & select.POLLERR:
            ret |= libvirt.VIR_EVENT_HANDLE_ERROR
        if events & select.POLLHUP:
            ret |= libvirt.VIR_EVENT_HANDLE_HANGUP
        return ret 
Example #22
Source File: test_IOManager.py    From redeem with GNU General Public License v3.0 5 votes vote down vote up
def test_sends_hangups(self):
    pipe = PipeWrapper()
    event = threading.Event()

    def callback(flag):
      if flag != select.POLLHUP and flag != select.POLLNVAL:
        self.assertEqual(flag, select.POLLHUP | select.POLLNVAL)
      event.set()

    self.manager.add_file(pipe.reader, callback)
    pipe.writer.close()
    event.wait(1)
    self.assertTrue(event.is_set()) 
Example #23
Source File: pprocess.py    From Aegean with Academic Free License v3.0 5 votes vote down vote up
def ready(self, timeout=None):

        """
        Wait for a period of time specified by the optional 'timeout' in
        milliseconds (or until communication is possible) and return a list of
        channels which are ready to be read from.
        """

        fds = self.poller.poll(timeout)
        readables = []
        self.removed = []

        for fd, status in fds:
            channel = self.readables[fd]
            removed = 0

            # Remove ended/error channels.

            if status & (select.POLLHUP | select.POLLNVAL | select.POLLERR):
                self.remove(channel)
                self.removed.append(channel)
                removed = 1

            # Record readable channels.

            if status & select.POLLIN:
                if not (removed and self.autoclose):
                    readables.append(channel)

        return readables 
Example #24
Source File: asyncore.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def readwrite(obj, flags):
    try:
        if flags & select.POLLIN:
            obj.handle_read_event()
        if flags & select.POLLOUT:
            obj.handle_write_event()
        if flags & select.POLLPRI:
            obj.handle_expt_event()
        if flags & (select.POLLHUP | select.POLLERR | select.POLLNVAL):
            obj.handle_close()
    except socket.error, e:
        if e.args[0] not in _DISCONNECTED:
            obj.handle_error()
        else:
            obj.handle_close() 
Example #25
Source File: asyncore.py    From canape with GNU General Public License v3.0 5 votes vote down vote up
def readwrite(obj, flags):
    try:
        if flags & select.POLLIN:
            obj.handle_read_event()
        if flags & select.POLLOUT:
            obj.handle_write_event()
        if flags & select.POLLPRI:
            obj.handle_expt_event()
        if flags & (select.POLLHUP | select.POLLERR | select.POLLNVAL):
            obj.handle_close()
    except socket.error, e:
        if e.args[0] not in _DISCONNECTED:
            obj.handle_error()
        else:
            obj.handle_close() 
Example #26
Source File: steps.py    From mittn with Apache License 2.0 5 votes vote down vote up
def step_impl(context):
    """Test that we have a correctly installed Burp Suite and the scanner driver available"""
    logging.getLogger("requests").setLevel(logging.WARNING)
    burpprocess = start_burp(context)

    # Send a message to headless-scanner-driver extension and wait for response.
    # Communicates to the scanner driver using a magical port number.
    # See https://github.com/F-Secure/headless-scanner-driver for additional documentation

    proxydict = {'http': 'http://' + context.burp_proxy_address,
                 'https': 'https://' + context.burp_proxy_address}
    try:
        requests.get("http://localhost:1111", proxies=proxydict)
    except requests.exceptions.RequestException as e:
        kill_subprocess(burpprocess)
        assert False, "Could not fetch scan item status over %s (%s). Is the proxy listener on?" % (
            context.burp_proxy_address, e)
    proxy_message = read_next_json(burpprocess)
    if proxy_message is None:
        kill_subprocess(burpprocess)
        assert False, "Timed out communicating to headless-scanner-driver " \
                      "extension over %s. Is something else running there?" \
                      % context.burp_proxy_address

    # Shut down Burp Suite. Again, see the scanner driver plugin docs for further info.

    poll = select.poll()
    poll.register(burpprocess.stdout, select.POLLNVAL | select.POLLHUP)  # pylint: disable-msg=E1101
    try:
        requests.get("http://localhost:1112", proxies=proxydict)
    except requests.exceptions.RequestException as e:
        kill_subprocess(burpprocess)
        assert False, "Could not fetch scan results over %s (%s)" % (context.burp_proxy_address, e)
    descriptors = poll.poll(10000)
    if descriptors == []:
        kill_subprocess(burpprocess)
        assert False, "Burp Suite clean exit took more than 10 seconds, killed"
    assert True 
Example #27
Source File: serialposix.py    From android_universal with MIT License 5 votes vote down vote up
def read(self, size=1):
        """\
        Read size bytes from the serial port. If a timeout is set it may
        return less characters as requested. With no timeout it will block
        until the requested number of bytes is read.
        """
        if not self.is_open:
            raise portNotOpenError
        read = bytearray()
        poll = select.poll()
        poll.register(self.fd, select.POLLIN | select.POLLERR | select.POLLHUP | select.POLLNVAL)
        if size > 0:
            while len(read) < size:
                # print "\tread(): size",size, "have", len(read)    #debug
                # wait until device becomes ready to read (or something fails)
                for fd, event in poll.poll(self._timeout * 1000):
                    if event & (select.POLLERR | select.POLLHUP | select.POLLNVAL):
                        raise SerialException('device reports error (poll)')
                    #  we don't care if it is select.POLLIN or timeout, that's
                    #  handled below
                buf = os.read(self.fd, size - len(read))
                read.extend(buf)
                if ((self._timeout is not None and self._timeout >= 0) or
                        (self._inter_byte_timeout is not None and self._inter_byte_timeout > 0)) and not buf:
                    break   # early abort on timeout
        return bytes(read) 
Example #28
Source File: asyncore.py    From unity-python with MIT License 5 votes vote down vote up
def poll2(timeout=0.0, map=None):
    # Use the poll() support added to the select module in Python 2.0
    if map is None:
        map = socket_map
    if timeout is not None:
        # timeout is in milliseconds
        timeout = int(timeout*1000)
    pollster = select.poll()
    if map:
        for fd, obj in map.items():
            flags = 0
            if obj.readable():
                flags |= select.POLLIN | select.POLLPRI
            # accepting sockets should not be writable
            if obj.writable() and not obj.accepting:
                flags |= select.POLLOUT
            if flags:
                # Only check for exceptions if object was either readable
                # or writable.
                flags |= select.POLLERR | select.POLLHUP | select.POLLNVAL
                pollster.register(fd, flags)
        try:
            r = pollster.poll(timeout)
        except select.error, err:
            if err.args[0] != EINTR:
                raise
            r = []
        for fd, flags in r:
            obj = map.get(fd)
            if obj is None:
                continue
            readwrite(obj, flags) 
Example #29
Source File: asyncore.py    From Splunking-Crime with GNU Affero General Public License v3.0 5 votes vote down vote up
def readwrite(obj, flags):
    try:
        if flags & select.POLLIN:
            obj.handle_read_event()
        if flags & select.POLLOUT:
            obj.handle_write_event()
        if flags & select.POLLPRI:
            obj.handle_expt_event()
        if flags & (select.POLLHUP | select.POLLERR | select.POLLNVAL):
            obj.handle_close()
    except socket.error, e:
        if e.args[0] not in _DISCONNECTED:
            obj.handle_error()
        else:
            obj.handle_close() 
Example #30
Source File: asyncore.py    From unity-python with MIT License 5 votes vote down vote up
def readwrite(obj, flags):
    try:
        if flags & select.POLLIN:
            obj.handle_read_event()
        if flags & select.POLLOUT:
            obj.handle_write_event()
        if flags & select.POLLPRI:
            obj.handle_expt_event()
        if flags & (select.POLLHUP | select.POLLERR | select.POLLNVAL):
            obj.handle_close()
    except socket.error, e:
        if e.args[0] not in _DISCONNECTED:
            obj.handle_error()
        else:
            obj.handle_close()