|
1 | 1 | """Provides classes that handle request dispatching."""
|
2 | 2 |
|
3 | 3 | from __future__ import print_function, unicode_literals
|
4 |
| - |
5 |
| -import socket |
6 |
| -import sys |
7 | 4 | import time
|
8 | 5 | from functools import wraps
|
9 |
| -from praw.errors import ClientException |
10 | 6 | from praw.helpers import normalize_url
|
11 | 7 | from requests import Session
|
12 | 8 | from six import text_type
|
13 |
| -from six.moves import cPickle # pylint: disable=F0401 |
14 | 9 | from threading import Lock
|
15 | 10 | from timeit import default_timer as timer
|
16 | 11 |
|
@@ -181,59 +176,3 @@ def evict(cls, urls):
|
181 | 176 | del cls.timeouts[key]
|
182 | 177 | return retval
|
183 | 178 | DefaultHandler.request = DefaultHandler.with_cache(RateLimitHandler.request)
|
184 |
| - |
185 |
| - |
186 |
| -class MultiprocessHandler(object): |
187 |
| - """A PRAW handler to interact with the PRAW multi-process server.""" |
188 |
| - |
189 |
| - def __init__(self, host='localhost', port=10101): |
190 |
| - """Construct an instance of the MultiprocessHandler.""" |
191 |
| - self.host = host |
192 |
| - self.port = port |
193 |
| - |
194 |
| - def _relay(self, **kwargs): |
195 |
| - """Send the request through the server and return the HTTP response.""" |
196 |
| - retval = None |
197 |
| - delay_time = 2 # For connection retries |
198 |
| - read_attempts = 0 # For reading from socket |
199 |
| - while retval is None: # Evict can return False |
200 |
| - sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
201 |
| - sock_fp = sock.makefile('rwb') # Used for pickle |
202 |
| - try: |
203 |
| - sock.connect((self.host, self.port)) |
204 |
| - cPickle.dump(kwargs, sock_fp, cPickle.HIGHEST_PROTOCOL) |
205 |
| - sock_fp.flush() |
206 |
| - retval = cPickle.load(sock_fp) |
207 |
| - except: # pylint: disable=W0702 |
208 |
| - exc_type, exc, _ = sys.exc_info() |
209 |
| - socket_error = exc_type is socket.error |
210 |
| - if socket_error and exc.errno == 111: # Connection refused |
211 |
| - sys.stderr.write('Cannot connect to multiprocess server. I' |
212 |
| - 's it running? Retrying in {0} seconds.\n' |
213 |
| - .format(delay_time)) |
214 |
| - time.sleep(delay_time) |
215 |
| - delay_time = min(64, delay_time * 2) |
216 |
| - elif exc_type is EOFError or socket_error and exc.errno == 104: |
217 |
| - # Failure during socket READ |
218 |
| - if read_attempts >= 3: |
219 |
| - raise ClientException('Successive failures reading ' |
220 |
| - 'from the multiprocess server.') |
221 |
| - sys.stderr.write('Lost connection with multiprocess server' |
222 |
| - ' during read. Trying again.\n') |
223 |
| - read_attempts += 1 |
224 |
| - else: |
225 |
| - raise |
226 |
| - finally: |
227 |
| - sock_fp.close() |
228 |
| - sock.close() |
229 |
| - if isinstance(retval, Exception): |
230 |
| - raise retval # pylint: disable=E0702 |
231 |
| - return retval |
232 |
| - |
233 |
| - def evict(self, urls): |
234 |
| - """Forward the eviction to the server and return its response.""" |
235 |
| - return self._relay(method='evict', urls=urls) |
236 |
| - |
237 |
| - def request(self, **kwargs): |
238 |
| - """Forward the request to the server and return its HTTP response.""" |
239 |
| - return self._relay(method='request', **kwargs) |
0 commit comments