Created
July 30, 2012 01:59
-
-
Save fsouza/3203281 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import time | |
import csp.csp as csp | |
@csp.process | |
def elevator(chan): | |
while True: | |
print "Transporting %s" % chan.read() | |
time.sleep(2) | |
@csp.process | |
def people(chan, names): | |
for name in names: | |
chan.write(name) | |
chan.poison() | |
if __name__ == "__main__": | |
names = ["Francisco", "Chico", "Maria", "José"] | |
chan = csp.Channel() | |
csp.Par(elevator(chan), elevator(chan), elevator(chan), people(chan, names)).start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -r bc4243a38823 csp/os_process.py | |
--- a/csp/os_process.py Sat Jan 07 02:21:59 2012 +0000 | |
+++ b/csp/os_process.py Sun Jul 29 22:55:08 2012 -0300 | |
@@ -262,7 +262,7 @@ | |
try: | |
self._target(*self._args, **self._kwargs) | |
except ChannelPoison: | |
- _debug('{0}s got ChannelPoison exception in {1}'.format((str(self), self.getPid()))) | |
+ _debug('{0}s got ChannelPoison exception in {1}'.format(str(self), self.getPid())) | |
self.referent_visitor(self._args + tuple(self._kwargs.values())) | |
# if self._popen is not None: self.terminate() | |
except KeyboardInterrupt: | |
@@ -892,7 +892,7 @@ | |
self.put(obj) | |
# Announce the object has been released to the reader. | |
self._available.release() | |
- _debug('++++ Writer on Channel {0}: _available: {1} _taken: {2}. '.format(self.name, self._available.get_value(), self._taken.get_value())) | |
+ _debug('++++ Writer on Channel {0}: _available: {1} _taken: {2}. '.format(self.name, repr(self._available), repr(self._taken))) | |
# Block until the object has been read. | |
self._taken.acquire() | |
# Remove the object from the channel. | |
@@ -907,7 +907,7 @@ | |
_debug('+++ Read on Channel {0} started.'.format(self.name)) | |
with self._rlock: # Protect from races between multiple readers. | |
# Block until an item is in the Channel. | |
- _debug('++++ Reader on Channel {0}: _available: {1} _taken: {2}. '.format(self.name, self._available.get_value(), self._taken.get_value())) | |
+ _debug('++++ Reader on Channel {0}: _available: {1} _taken: {2}. '.format(self.name, repr(self._available), repr(self._taken))) | |
self._available.acquire() | |
# Get the item. | |
obj = self.get() | |
@@ -935,7 +935,7 @@ | |
self._is_selectable.value = Channel.TRUE | |
else: | |
self._is_selectable.value = Channel.FALSE | |
- _debug('Enable on guard {0} _is_selectable: {1} _available: {2}'.format(self.name, str(self._is_selectable.value), str(self._available.get_value()))) | |
+ _debug('Enable on guard {0} _is_selectable: {1} _available: {2}'.format(self.name, str(self._is_selectable.value), repr(self._available))) | |
def disable(self): | |
"""Disable this channel for Alt selection. | |
@@ -956,7 +956,7 @@ | |
_debug('channel select starting') | |
assert self._is_selectable.value == Channel.TRUE | |
with self._rlock: | |
- _debug('got read lock on channel {0} _available: {1}'.format(self.name, str(self._available.get_value()))) | |
+ _debug('got read lock on channel {0} _available: {1}'.format(self.name, repr(self._available))) | |
# Obtain object on Channel. | |
obj = self.get() | |
_debug('got obj') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment