mirror of
https://github.com/django/daphne.git
synced 2025-07-11 08:22:17 +03:00
Merge pull request #8 from octaflop/doc-update
updated docs, updated gitignore
This commit is contained in:
commit
10df1c2c32
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,3 +1,6 @@
|
||||||
*.egg-info
|
*.egg-info
|
||||||
dist/
|
dist/
|
||||||
docs/_build
|
docs/_build
|
||||||
|
__pycache__/
|
||||||
|
*.swp
|
||||||
|
|
||||||
|
|
|
@ -35,5 +35,5 @@ class Worker(object):
|
||||||
except Message.Requeue:
|
except Message.Requeue:
|
||||||
self.channel_backend.send(channel, content)
|
self.channel_backend.send(channel, content)
|
||||||
except:
|
except:
|
||||||
print "Error processing message with consumer %s:" % name_that_thing(consumer)
|
print("Error processing message with consumer {}:".format(name_that_thing(consumer)))
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
|
@ -46,7 +46,7 @@ The channels have capacity, so a load of producers can write lots of messages
|
||||||
into a channel with no consumers and then a consumer can come along later and
|
into a channel with no consumers and then a consumer can come along later and
|
||||||
will start getting served those queued messages.
|
will start getting served those queued messages.
|
||||||
|
|
||||||
If you've used channels in Go, these are reasonably similar to those. The key
|
If you've used `channels in Go <https://gobyexample.com/channels>`_, these are reasonably similar to those. The key
|
||||||
difference is that these channels are network-transparent; the implementations
|
difference is that these channels are network-transparent; the implementations
|
||||||
of channels we provide are all accessible across a network to consumers
|
of channels we provide are all accessible across a network to consumers
|
||||||
and producers running in different processes or on different machines.
|
and producers running in different processes or on different machines.
|
||||||
|
@ -161,7 +161,7 @@ and be less than 200 characters long.
|
||||||
|
|
||||||
It's optional for a backend implementation to understand this - after all,
|
It's optional for a backend implementation to understand this - after all,
|
||||||
it's only important at scale, where you want to shard the two types differently
|
it's only important at scale, where you want to shard the two types differently
|
||||||
- but it's present nonetheless. For more on scaling, and how to handle channel
|
— but it's present nonetheless. For more on scaling, and how to handle channel
|
||||||
types if you're writing a backend or interface server, read :doc:`scaling`.
|
types if you're writing a backend or interface server, read :doc:`scaling`.
|
||||||
|
|
||||||
Groups
|
Groups
|
||||||
|
|
|
@ -71,6 +71,8 @@ do any time. Let's try some WebSockets, and make a basic chat server!
|
||||||
Delete that consumer and its routing - we'll want the normal Django view layer to
|
Delete that consumer and its routing - we'll want the normal Django view layer to
|
||||||
serve HTTP requests from now on - and make this WebSocket consumer instead::
|
serve HTTP requests from now on - and make this WebSocket consumer instead::
|
||||||
|
|
||||||
|
from channels import Group
|
||||||
|
|
||||||
def ws_add(message):
|
def ws_add(message):
|
||||||
Group("chat").add(message.reply_channel)
|
Group("chat").add(message.reply_channel)
|
||||||
|
|
||||||
|
@ -105,6 +107,8 @@ so we can hook that up to re-add the channel (it's safe to add the channel to
|
||||||
a group it's already in - similarly, it's safe to discard a channel from a
|
a group it's already in - similarly, it's safe to discard a channel from a
|
||||||
group it's not in)::
|
group it's not in)::
|
||||||
|
|
||||||
|
from channels import Group
|
||||||
|
|
||||||
# Connected to websocket.keepalive
|
# Connected to websocket.keepalive
|
||||||
def ws_keepalive(message):
|
def ws_keepalive(message):
|
||||||
Group("chat").add(message.reply_channel)
|
Group("chat").add(message.reply_channel)
|
||||||
|
@ -123,6 +127,8 @@ And, even though channels will expire out, let's add an explicit ``disconnect``
|
||||||
handler to clean up as people disconnect (most channels will cleanly disconnect
|
handler to clean up as people disconnect (most channels will cleanly disconnect
|
||||||
and get this called)::
|
and get this called)::
|
||||||
|
|
||||||
|
from channels import Group
|
||||||
|
|
||||||
# Connected to websocket.disconnect
|
# Connected to websocket.disconnect
|
||||||
def ws_disconnect(message):
|
def ws_disconnect(message):
|
||||||
Group("chat").discard(message.reply_channel)
|
Group("chat").discard(message.reply_channel)
|
||||||
|
|
|
@ -19,3 +19,16 @@ Once that's done, you should add ``channels`` to your
|
||||||
|
|
||||||
That's it! Once enabled, ``channels`` will integrate itself into Django and
|
That's it! Once enabled, ``channels`` will integrate itself into Django and
|
||||||
take control of the ``runserver`` command. See :doc:`getting-started` for more.
|
take control of the ``runserver`` command. See :doc:`getting-started` for more.
|
||||||
|
|
||||||
|
|
||||||
|
Installing the lastest development version
|
||||||
|
------------------------------------------
|
||||||
|
|
||||||
|
To install the latest version of Channels, clone the repo, change to the repo,
|
||||||
|
change to the repo directory, and pip install it into your current virtual
|
||||||
|
environment::
|
||||||
|
|
||||||
|
$ git clone git@github.com:andrewgodwin/channels.git
|
||||||
|
$ cd channels
|
||||||
|
$ <activate your project’s virtual environment>
|
||||||
|
(environment) $ pip install -e . # the dot specifies the current repo
|
||||||
|
|
Loading…
Reference in New Issue
Block a user