Skip to content

Commit

Permalink
Removed praw-multiprocess and MultiProcessHandler.
Browse files Browse the repository at this point in the history
  • Loading branch information
bboe committed Feb 22, 2016
1 parent ac6fcdd commit 252083e
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 254 deletions.
8 changes: 8 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ upstream changes.
.. begin_changelog_body
4.0.0a1
-------

**Removed**

* Removed `praw-multiprocess` and its associated ``MultiprocessHandler``. This
functionality is no longer needed with PRAW4.

3.4.0 (2016-02-21)
------------------

Expand Down
1 change: 0 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ Content Pages
pages/comment_parsing
pages/oauth
pages/lazy-loading
pages/multiprocess
pages/contributor_guidelines
pages/configuration_files
pages/faq
Expand Down
85 changes: 0 additions & 85 deletions docs/pages/multiprocess.rst

This file was deleted.

4 changes: 1 addition & 3 deletions docs/pages/oauth.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ Step 2: Setting up PRAW.

If you want to persist instances of PRAW across multiple requests in a web
application, we recommend that you create an new instance per distinct
authentication. Furthermore, if your web application spawns multiple
processes, it is highly recommended that you utilize PRAW's
:ref:`multiprocess <multiprocess>` functionality.
authentication.

We start as usual by importing the PRAW package and creating a :class:`.Reddit`
object with a clear and descriptive useragent that follows the `api rules
Expand Down
61 changes: 0 additions & 61 deletions praw/handlers.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
"""Provides classes that handle request dispatching."""

from __future__ import print_function, unicode_literals

import socket
import sys
import time
from functools import wraps
from praw.errors import ClientException
from praw.helpers import normalize_url
from requests import Session
from six import text_type
from six.moves import cPickle # pylint: disable=F0401
from threading import Lock
from timeit import default_timer as timer

Expand Down Expand Up @@ -181,59 +176,3 @@ def evict(cls, urls):
del cls.timeouts[key]
return retval
DefaultHandler.request = DefaultHandler.with_cache(RateLimitHandler.request)


class MultiprocessHandler(object):
"""A PRAW handler to interact with the PRAW multi-process server."""

def __init__(self, host='localhost', port=10101):
"""Construct an instance of the MultiprocessHandler."""
self.host = host
self.port = port

def _relay(self, **kwargs):
"""Send the request through the server and return the HTTP response."""
retval = None
delay_time = 2 # For connection retries
read_attempts = 0 # For reading from socket
while retval is None: # Evict can return False
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock_fp = sock.makefile('rwb') # Used for pickle
try:
sock.connect((self.host, self.port))
cPickle.dump(kwargs, sock_fp, cPickle.HIGHEST_PROTOCOL)
sock_fp.flush()
retval = cPickle.load(sock_fp)
except: # pylint: disable=W0702
exc_type, exc, _ = sys.exc_info()
socket_error = exc_type is socket.error
if socket_error and exc.errno == 111: # Connection refused
sys.stderr.write('Cannot connect to multiprocess server. I'
's it running? Retrying in {0} seconds.\n'
.format(delay_time))
time.sleep(delay_time)
delay_time = min(64, delay_time * 2)
elif exc_type is EOFError or socket_error and exc.errno == 104:
# Failure during socket READ
if read_attempts >= 3:
raise ClientException('Successive failures reading '
'from the multiprocess server.')
sys.stderr.write('Lost connection with multiprocess server'
' during read. Trying again.\n')
read_attempts += 1
else:
raise
finally:
sock_fp.close()
sock.close()
if isinstance(retval, Exception):
raise retval # pylint: disable=E0702
return retval

def evict(self, urls):
"""Forward the eviction to the server and return its response."""
return self._relay(method='evict', urls=urls)

def request(self, **kwargs):
"""Forward the request to the server and return its HTTP response."""
return self._relay(method='request', **kwargs)
102 changes: 0 additions & 102 deletions praw/multiprocess.py

This file was deleted.

2 changes: 0 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
description=('PRAW, an acronym for `Python Reddit API Wrapper`, is a '
'python package that allows for simple access to '
'reddit\'s API.'),
entry_points={'console_scripts': [
'praw-multiprocess = praw.multiprocess:run']},
install_requires=['decorator >=4.0.9, <4.1',
'requests >=2.3.0',
'six ==1.10',
Expand Down

0 comments on commit 252083e

Please sign in to comment.