Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
Conflicts:
	pyramid_socketio/io.py
  • Loading branch information
abourget committed Mar 5, 2012
2 parents 7c130ce + 11a2bab commit 38446ae
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 36 deletions.
80 changes: 55 additions & 25 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,41 +1,71 @@
0.8:
Changelog
=========

- Fixed a bug when killing sessions.

0.9 (unreleased)
----------------

0.7:
- ``socketio-serve-reload`` did not not find the ``socketio-serve``-executable
in some cases.
[WouterVH]

- Added on_disconnect callbacks.
- Improved kill() which will make it recursive by default, and call the on_disconnect callbacks.
- spawn() now allows paramters (*args, **kwargs) to be passed in.
- Improved documentation
- msg() and error() now use send() which has all the connection state verification, and killing mechanism.

0.6:
0.8 (2011-05-30)
----------------

- Fixed a bug with .ini files with no logging sections (like formatters)
- Fixed a bug when killing sessions.

0.5:

- Added JavaScript example.
- Fixed setup.py (having not included CHANGES.txt in the sdist)
0.7 (2011-05-17)
----------------

0.4
- Added on_disconnect callbacks.

- Updated docs.
- Improved kill() which will make it recursive by default, and call the on_disconnect callbacks.

0.3
- spawn() now allows paramters (*args, **kwargs) to be passed in.

- CHANGES and README added to description.
- Improved documentation

0.2
- msg() and error() now use send() which has all the connection state verification, and killing mechanism.

- Help updated

0.1
0.6 (2011-05-11)
----------------

- Initial release
- Support for paster server plugin
- Provide with command-line servers
- socketio-serve
- socketio-serve-reload
- Fixed a bug with .ini files with no logging sections (like formatters)


0.5 (2011-02-15)
----------------

- Added JavaScript example.
- Fixed setup.py (having not included CHANGES.txt in the sdist)


0.4 (2011-02-15)
----------------

- Updated docs.


0.3 (2011-02-15)
----------------

- CHANGES and README added to description.


0.2 (2011-02-15)
----------------

- Help updated


0.1 (2011-02-15)
----------------

- Initial release
- Support for paster server plugin
- Provide with command-line servers
- socketio-serve
- socketio-serve-reload
21 changes: 13 additions & 8 deletions pyramid_socketio/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,24 @@
import logging
import gevent

__all__ = ['SocketIOError', 'SocketIOContext',
'socketio_manage']
__all__ = ['SocketIOError', 'SocketIOContext', 'socketio_manage']

log = logging.getLogger(__name__)


class SocketIOError(Exception):
pass


class SocketIOKeyAssertError(SocketIOError):
pass


class SocketIOContext(object):
def __init__(self, request, in_type="type", out_type="type", debug=False,
json_dumps=None, json_loads=None):
"""Called when you create a new context, either by hand or from a nested context.
"""Called when you create a new context, either by hand or from a
nested context.
Arguments:
* ``request`` - the pyramid request
Expand Down Expand Up @@ -49,7 +52,7 @@ def __init__(self, request, in_type="type", out_type="type", debug=False,

# Override self.debug if in production mode
if not debug:
self.debug = lambda x: None
self.debug = lambda x: None

def debug(self, msg):
print "%s: %s" % (self.id, msg)
Expand Down Expand Up @@ -104,7 +107,6 @@ def kill(self, recursive=True):
if io:
io.session.kill()
return


def switch(self, new_context, *args, **kwargs):
"""Switch context, stack up contexts and pass on request.
Expand Down Expand Up @@ -151,7 +153,6 @@ def send(self, msg):
raise gevent.GreenletExit()
self.io.send(msg)


def assert_keys(self, msg, elements):
"""Make sure the elements are inside the message, otherwise send an
error message and skip the message.
Expand Down Expand Up @@ -181,7 +182,8 @@ def __call__(self, msg):


def watcher(request):
"""Watch if any of the greenlets for a request have died. If so, kill the request and the socket.
"""Watch if any of the greenlets for a request have died. If so, kill the
request and the socket.
"""
# TODO: add that if any of the request.jobs die, kill them all and exit
io = request.environ['socketio']
Expand All @@ -193,6 +195,7 @@ def watcher(request):
gevent.killall(request.jobs)
return


def socketio_recv(context):
"""Manage messages arriving from Socket.IO, dispatch to context handler"""
io = context.io
Expand All @@ -215,8 +218,10 @@ def socketio_recv(context):
context = newctx

if not io.connected():
context.kill()
return


def socketio_manage(start_context):
"""Main SocketIO management function, call from within your Pyramid view.
Expand All @@ -238,7 +243,7 @@ def socketio_manage(start_context):
killall = gevent.spawn(watcher, request)

gevent.joinall(request.jobs + [killall])

start_context.debug("socketio_manage terminated")

return "done"
1 change: 1 addition & 0 deletions pyramid_socketio/pasteserve.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
__all__ = ["server_factory",
"server_factory_patched"]


def server_factory(global_conf, host, port, resource="socket.io"):
port = int(port)
def serve(app):
Expand Down
8 changes: 7 additions & 1 deletion pyramid_socketio/servereload.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@
import os
import sys

from os.path import dirname, join,realpath


def socketio_serve_reload():
"""Spawn a new process and reload when it dies"""
bin_dir = dirname(realpath(sys.argv[0]))
executable = join(bin_dir, 'socketio-serve')
command = "%s --watch %s" % (executable, sys.argv[1])
while True:
ret = os.system("socketio-serve --watch %s" % (sys.argv[1]))
ret = os.system(command)
if ret != 768:
break
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
packages=find_packages(),
include_package_data=True,
zip_safe=False,
install_requires = requires,
entry_points = """\
install_requires=requires,
entry_points="""\
[console_scripts]
socketio-serve-reload = pyramid_socketio.servereload:socketio_serve_reload
socketio-serve = pyramid_socketio.serve:socketio_serve
Expand Down

0 comments on commit 38446ae

Please sign in to comment.