Skip to content
This repository has been archived by the owner on Jun 4, 2023. It is now read-only.

Commit

Permalink
don't immediately crash when importing Pyro4 when the selectors/selec…
Browse files Browse the repository at this point in the history
…tors34 module is not available, but raise a meaningful exception instead. (added to facilitate Debian, that doesn't package this module at this time)
  • Loading branch information
irmen committed Jan 28, 2017
1 parent b9abeea commit edfdbb2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ Change Log
to be the user's problem if they attempt to use this combination.
- Fixed a few IronPython issues with several unit tests.
- Applied version detection patch from Debian package to contrib/init.d/pyro4-nsd
- Don't crash immediately at importing Pyro4 when the 'selectors' or 'selectors34' module is not available.
(This is normally a required dependency so the situation should not occur.
But it is problematic on Debian (and perhaps other distributions) at this time, because this module is not packaged.
So we now raise a proper error message, but only when an attempt is made to actually create a multiplex server.
Note that all other parts of Pyro4 are usable just fine in this case. The problem is absent when using Python 3.4 or newer.)


**Pyro 4.53**
Expand Down
8 changes: 7 additions & 1 deletion src/Pyro4/socketserver/multiplexserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
try:
import selectors
except ImportError:
import selectors34 as selectors
try:
import selectors34 as selectors
except ImportError:
selectors = None
from Pyro4 import socketutil, errors, util
import Pyro4.constants

Expand All @@ -26,6 +29,9 @@ class SocketServer_Multiplex(object):
"""Multiplexed transport server for socket connections (uses select, poll, kqueue, ...)"""
def __init__(self):
self.sock = self.daemon = self.locationStr = None
if selectors is None:
raise RuntimeError("This Python installation doesn't have the 'selectors34' module installed, " +
"which is required to use Pyro's multiplex server. Install it, or use the threadpool server instead.")
self.selector = selectors.DefaultSelector()
self.shutting_down = False

Expand Down

0 comments on commit edfdbb2

Please sign in to comment.