Example #1
0
    def test_interrupt_socket(self):
        interrupt_socket = InterruptSocket()
        self.assertTrue(interrupt_socket.ip, u"127.0.0.1")
        self.assertIsInstance(interrupt_socket.port, int)
        self.assertIsInstance(interrupt_socket.socket, socket.socket)

        interrupt_socket.interrupt()
        interrupt_socket.interrupt()
        interrupt_socket.close()
Example #2
0
    def test_interrupt_socket(self):
        interrupt_socket = InterruptSocket()
        self.assertTrue(interrupt_socket.ip, u"127.0.0.1")
        self.assertIsInstance(interrupt_socket.port, int)
        self.assertIsInstance(interrupt_socket.socket, socket.socket)

        interrupt_socket.interrupt()
        interrupt_socket.interrupt()
        interrupt_socket.close()
Example #3
0
class TorrentCheckerThread(Thread):
    """
    Thread used to monitor for data arriving on the scrape sockets.
    """
    def __init__(self, tracker_checker):
        super(TorrentCheckerThread, self).__init__(name=u"torrent_checker")
        self._logger = logging.getLogger(self.__class__.__name__)
        self._torrent_checker = tracker_checker

        self._interrupt_socket = InterruptSocket()

        self._session_dict = {}

    def cleanup(self):
        self._session_dict = None
        self._interrupt_socket.close()
        self._interrupt_socket = None

    def interrupt(self):
        self._interrupt_socket.interrupt()

    def run(self):
        """
        Checks for data in the scrape sockets until it's time to stop.
        Every time there's data on one of the sockets, TorrentChecker.check_sessions() will be called.
        """
        check_read_socket_list = []
        check_write_socket_list = []
        while not self._torrent_checker.should_stop:
            check_read_socket_list.append(self._interrupt_socket.socket)

            read_socket_list, write_socket_list, _ = select.select(
                check_read_socket_list, check_write_socket_list, [], 5)

            if self._torrent_checker.should_stop:
                break

            if self._interrupt_socket.socket in read_socket_list:
                self._interrupt_socket.clear()
                read_socket_list = [
                    sock for sock in read_socket_list
                    if sock != self._interrupt_socket.socket
                ]

            result = self._torrent_checker.check_sessions(
                read_socket_list, write_socket_list, [])

            if result is None:
                break
            check_read_socket_list, check_write_socket_list = result

        self.cleanup()
        self._logger.info(u"stopped")
Example #4
0
class TorrentCheckerThread(Thread):

    """
    Thread used to monitor for data arriving on the scrape sockets.
    """

    def __init__(self, tracker_checker):
        super(TorrentCheckerThread, self).__init__(name=u"torrent_checker")
        self._logger = logging.getLogger(self.__class__.__name__)
        self._torrent_checker = tracker_checker

        self._interrupt_socket = InterruptSocket()

        self._session_dict = {}

    def cleanup(self):
        self._session_dict = None
        self._interrupt_socket.close()
        self._interrupt_socket = None

    def interrupt(self):
        self._interrupt_socket.interrupt()

    def run(self):
        """
        Checks for data in the scrape sockets until it's time to stop.
        Every time there's data on one of the sockets, TorrentChecker.check_sessions() will be called.
        """
        check_read_socket_list = []
        check_write_socket_list = []
        while not self._torrent_checker.should_stop:
            check_read_socket_list.append(self._interrupt_socket.socket)

            read_socket_list, write_socket_list, _ = select.select(check_read_socket_list,
                                                                   check_write_socket_list,
                                                                   [], 5)

            if self._torrent_checker.should_stop:
                break

            if self._interrupt_socket.socket in read_socket_list:
                self._interrupt_socket.clear()
                read_socket_list = [sock for sock in read_socket_list if sock != self._interrupt_socket.socket]

            result = self._torrent_checker.check_sessions(read_socket_list, write_socket_list, [])

            if result is None:
                break
            check_read_socket_list, check_write_socket_list = result

        self.cleanup()
        self._logger.info(u"stopped")