# 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")
    ):
        self.memory_data.append((time_seconds, self.process.memory_full_info().uss))
    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.MemoryError'>:
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\Core\Modules\resource_monitor.py:48:check_resources
lib\site-packages\psutil\__init__.py:1139:memory_full_info
lib\site-packages\psutil\_pswindows.py:636:wrapper
lib\site-packages\psutil\_pswindows.py:760:memory_full_info
]

# 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)

    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))