Skip to content

Commit

Permalink
Merge pull request #7659 from drew2a/feature/debug_for_requests
Browse files Browse the repository at this point in the history
Add the debug parameter to the `RequestManager.add()`
  • Loading branch information
drew2a committed Oct 31, 2023
2 parents d58b2f9 + f0faa25 commit 1ca3e62
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/tribler/gui/network/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def __init__(
self.status_text = "unknown"
self.cancellable = True
self.id = 0
self.caller = ''

def set_manager(self, manager: RequestManager):
self.manager = manager
Expand Down Expand Up @@ -184,4 +185,7 @@ def _delete(self):
self.reply = None

def __str__(self):
return f'{self.method} {self.url}'
result = f'{self.method} {self.url}'
if self.caller:
result += f'\nCaller: {self.caller}'
return result
13 changes: 12 additions & 1 deletion src/tribler/gui/network/request_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import json
import logging
import traceback
from collections import deque
from time import time
from typing import Callable, Dict, Optional, Set
Expand Down Expand Up @@ -118,10 +119,20 @@ def delete(self,
method=Request.DELETE)
return self.add(request)

def add(self, request: Request) -> Optional[Request]:
def add(self, request: Request, debug: bool = False) -> Optional[Request]:
""" Add a request to the queue.
Args:
request: The request to add.
debug: Whether to print debug information.
Returns: The request if it was added, None otherwise.
"""
if self._is_in_shutting_down(request):
# Do not send requests when Tribler is shutting down
return None
if debug:
request.caller = traceback.extract_stack()[-3]

# Set last request id
self.last_request_id += 1
Expand Down

0 comments on commit 1ca3e62

Please sign in to comment.