# Buggy code
def check_resources(self):
    """
    Check CPU and memory usage.
    """
    self._logger.debug("Checking memory/CPU usage")
    if len(self.cpu_data) == self.history_size:
        self.cpu_data.pop(0)
    if len(self.memory_data) == self.history_size:
        self.memory_data.pop(0)

    time_seconds = time.time()
    self.cpu_data.append((time_seconds, self.process.cpu_percent(interval=None)))

    # Get the memory usage of the process
    # psutil package 4.0.0 introduced memory_full_info() method which among other info also returns uss.
    # uss (Unique Set Size) is probably the most representative metric for determining how much memory is
    # actually being used by a process.
    # However, on psutil version < 4.0.0, we fallback to use rss (Resident Set Size) which is the non-swapped
    # physical memory a process has used
    if hasattr(self.process, "memory_full_info") and callable(
        getattr(self.process, "memory_full_info")
    ):
        try:
            self.memory_data.append((time_seconds, self.process.memory_full_info().uss))
        except Exception as e:
            # Can be MemoryError or WindowsError, which isn't defined on Linux
            # Catching a WindowsError would therefore error out the error handler itself on Linux
            self._logger.error("Failed to get memory full info: %s", str(e))
    elif hasattr(self.process, "memory_info") and callable(
        getattr(self.process, "memory_info")
    ):
        self.memory_data.append((time_seconds, self.process.memory_info().rss))


# Traceback (RuntimeError)
Traceback (most recent call last):
File "TriblerGUI\event_request_manager.py", line 99, in on_read_data
RuntimeError: [Failure instance: Traceback: <type 'exceptions.IOError'>: [Errno 28] No space left on device
lib\site-packages\twisted\internet\base.py:1243:run
lib\site-packages\twisted\internet\base.py:1252:mainLoop
lib\site-packages\twisted\internet\base.py:878:runUntilCurrent
lib\site-packages\twisted\internet\task.py:239:__call__
--- <exception caught here> ---
lib\site-packages\twisted\internet\defer.py:150:maybeDeferred
Tribler\dispersy\discovery\community.py:809:clean_and_save
]

# Fixed code
def check_resources(self):
    """
    Check CPU and memory usage.
    """
    self._logger.debug("Checking memory/CPU usage")
    if len(self.cpu_data) == self.history_size:
        self.cpu_data.pop(0)
    if len(self.memory_data) == self.history_size:
        self.memory_data.pop(0)
    if len(self.disk_usage_data) == self.history_size:
        self.disk_usage_data.pop(0)

    time_seconds = time.time()
    self.cpu_data.append((time_seconds, self.process.cpu_percent(interval=None)))

    # Get the memory usage of the process
    # psutil package 4.0.0 introduced memory_full_info() method which among other info also returns uss.
    # uss (Unique Set Size) is probably the most representative metric for determining how much memory is
    # actually being used by a process.
    # However, on psutil version < 4.0.0, we fallback to use rss (Resident Set Size) which is the non-swapped
    # physical memory a process has used
    if hasattr(self.process, "memory_full_info") and callable(
        getattr(self.process, "memory_full_info")
    ):
        try:
            self.memory_data.append((time_seconds, self.process.memory_full_info().uss))
        except Exception as e:
            # Can be MemoryError or WindowsError, which isn't defined on Linux
            # Catching a WindowsError would therefore error out the error handler itself on Linux
            self._logger.error("Failed to get memory full info: %s", str(e))
    elif hasattr(self.process, "memory_info") and callable(
        getattr(self.process, "memory_info")
    ):
        self.memory_data.append((time_seconds, self.process.memory_info().rss))

    # Check for available disk space
    disk_usage = psutil.disk_usage(self.session.get_state_dir())
    self.disk_usage_data.append(
        {
            "time": time_seconds,
            "total": disk_usage.total,
            "used": disk_usage.used,
            "free": disk_usage.free,
            "percent": disk_usage.percent,
        }
    )

    # Notify session if less than 100MB of disk space is available
    if disk_usage.free < 10000 * (1024 * 1024):
        self._logger.warn("Warning! Less than 100MB of disk space available")
        self.session.notifier.notify(
            SIGNAL_RESOURCE_CHECK, SIGNAL_LOW_SPACE, None, self.disk_usage_data[-1]
        )