Invokes requests.method(url, *args, **kwargs) on a background thread, and immediately returns. If method() raises an exception, it is logged, unless log_errors=False.
(self, method, url, *args, **kwargs)
| 114 | return WebRequest("post", *args, **kwargs) |
| 115 | |
| 116 | def __init__(self, method, url, *args, **kwargs): |
| 117 | """Invokes requests.method(url, *args, **kwargs) on a background thread, |
| 118 | and immediately returns. |
| 119 | |
| 120 | If method() raises an exception, it is logged, unless log_errors=False. |
| 121 | """ |
| 122 | |
| 123 | self.method = method |
| 124 | self.url = url |
| 125 | |
| 126 | self.log_errors = kwargs.pop("log_errors", True) |
| 127 | |
| 128 | self.request = None |
| 129 | """The underlying requests.Request object. |
| 130 | |
| 131 | Not set until wait_for_response() returns. |
| 132 | """ |
| 133 | |
| 134 | self.exception = None |
| 135 | """Exception that occurred while performing the request, if any. |
| 136 | |
| 137 | Not set until wait_for_response() returns. |
| 138 | """ |
| 139 | |
| 140 | log.info("{0}", self) |
| 141 | |
| 142 | func = getattr(requests, method) |
| 143 | self._worker_thread = threading.Thread( |
| 144 | target=lambda: self._worker(func, *args, **kwargs), |
| 145 | name=f"WebRequest({self})", |
| 146 | ) |
| 147 | self._worker_thread.daemon = True |
| 148 | self._worker_thread.start() |
| 149 | |
| 150 | def __str__(self): |
| 151 | return f"HTTP {self.method.upper()} {self.url}" |