Skip to content

Commit

Permalink
Formal fixes (spacing, line lengths)
Browse files Browse the repository at this point in the history
  • Loading branch information
rgalanakis committed Jun 12, 2014
1 parent f0d6b2f commit 707f365
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 11 deletions.
1 change: 1 addition & 0 deletions examples/futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import goless


# First create the async versions built on promises
def inverse_async(future):
c = goless.chan()
Expand Down
3 changes: 1 addition & 2 deletions examples/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from __future__ import print_function

import hashlib

import os

import goless
Expand All @@ -28,7 +27,7 @@ def pipeline():
def scanner():
for d, dn, f in os.walk('.'):
for fn in f:
files.send(os.path.join(d,fn))
files.send(os.path.join(d, fn))
files.close()

def hasher():
Expand Down
4 changes: 2 additions & 2 deletions examples/producer_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
def main():
done = goless.chan()
msgs = goless.chan()
out = goless.chan()
out = goless.chan()

def produce():
for i in range(10):
Expand All @@ -26,7 +26,7 @@ def produce():

def consume(name):
for msg in msgs:
out.send('%s:%s ' % (name,msg))
out.send('%s:%s ' % (name, msg))

def logger():
for msg in out:
Expand Down
1 change: 0 additions & 1 deletion goless/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import logging
import sys

import traceback

from .backends import current as _be
Expand Down
1 change: 1 addition & 0 deletions goless/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ def calculate_backend(name_from_env, backends=None):
raise RuntimeError(
'Invalid backend %r specified. Valid backends are: %s'
% (name_from_env, _default_backends.keys()))
# noinspection PyCallingNonCallable
return backends[name_from_env]()
try:
return _calc_default(backends)
Expand Down
18 changes: 13 additions & 5 deletions goless/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def recv(self):
"""
Receive a value from the channel.
Receiving will always block if no value is available.
If the channel is already closed, :class:`goless.ChannelClosed` will be raised.
If the channel is already closed,
:class:`goless.ChannelClosed` will be raised.
If the channel closes during a blocking ``recv``,
:class:`goless.ChannelClosed` will be raised. (#TODO)
"""
Expand Down Expand Up @@ -72,8 +73,10 @@ def send_ready(self):
def close(self):
"""
Closes the channel, not allowing further communication.
Any blocking senders or receivers will be woken up and raise :class:`goless.ChannelClosed`.
Receiving or sending to a closed channel will raise :class:`goless.ChannelClosed`.
Any blocking senders or receivers will be woken up and
raise :class:`goless.ChannelClosed`.
Receiving or sending to a closed channel
will raise :class:`goless.ChannelClosed`.
"""
self._closed = True

Expand Down Expand Up @@ -149,7 +152,11 @@ def recv_ready(self):
return self.values_deque or self.waiting_chan.balance > 0

def send_ready(self):
return len(self.values_deque) < self.maxsize or self.waiting_chan.balance < 0
room_in_queue = len(self.values_deque) < self.maxsize
if room_in_queue:
return True
receivers_waiting = self.waiting_chan.balance < 0
return receivers_waiting

def close(self):
# This next yield gives a chance to all blocked receivers to return
Expand All @@ -161,7 +168,8 @@ def close(self):
# but still get a ChannelClosed error.
_be.yield_()
# To make sure all pending tasklets are woken up,
# we mark the channel closed and then spam out sends or receives if needed.
# we mark the channel closed and then spam out sends or
# receives if needed.
# The tasklets will wake up, see the channel is closed,
# and raise a ChannelClosed error.
GoChannel.close(self)
Expand Down
3 changes: 2 additions & 1 deletion goless/selecting.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ def exec_(self):

# noinspection PyPep8Naming,PyShadowingNames
class scase(object):
"""A case that will ``chan.send(value)`` when the channel is able to send."""
"""A case that will ``chan.send(value)``
when the channel is able to send."""
def __init__(self, chan, value):
self.chan = chan
self.value = value
Expand Down

0 comments on commit 707f365

Please sign in to comment.