Пример #1
0
# cocrash.py
#
# An example of hooking coroutines up in a way that might cause a potential
# crash.   Basically, there are two threads feeding data into the
# printer() coroutine.

from cobroadcast import *
from cothread import threaded

p = printer()
target = broadcast([threaded(grep("foo", p)), threaded(grep("bar", p))])

# Adjust the count if this doesn't cause a crash
for i in range(10):
    target.send("foo is nice\n")
    target.send("bar is bad\n")

del target
del p
Пример #2
0
                elif event == 'text':
                    fragments.append(value)
                elif event == 'end':
                    if value != 'bus':
                        busdict[value] = "".join(fragments)
                    else:
                        target.send(busdict)
                        break


@asyncio.coroutine
def filter_on_field(fieldname, value, target):
    while True:
        d = (yield)
        if d.get(fieldname) == value:
            target.send(d)


b


@asyncio.coroutine
def bus_locations():
    while True:
        bus = (yield)
        print(bus)


xml.sax.parse('some.xml',
              EventHandler(buses_to_dicts(threaded(bus_locations()))))
Пример #3
0
# cocrash.py
#
# An example of hooking coroutines up in a way that might cause a potential
# crash.   Basically, there are two threads feeding data into the
# printer() coroutine.

from cobroadcast import *
from cothread import threaded

p = printer()
target = broadcast([threaded(grep('foo', p)),
                    threaded(grep('bar', p))])

# Adjust the count if this doesn't cause a crash
for i in xrange(10):
    target.send("foo is nice\n")
    target.send("bar is bad\n")

del target
del p
Пример #4
0
# cocrash.py
#
# An example of hooking coroutines up in a way that might cause a potential
# crash.   Basically, there are two threads feeding data into the
# printer() coroutine.

from cobroadcast import *
from cothread import threaded

p = printer()
target = broadcast([threaded(grep('foo',p)),
                    threaded(grep('bar',p))])

# Adjust the count if this doesn't cause a crash
for i in xrange(10):
    target.send("foo is nice\n")
    target.send("bar is bad\n")

del target
del p
Пример #5
0
                        fragment = []
                    if event == 'content':
                        fragment.append(value)
                    if event == 'end':
                        if value != 'bus':
                            buses[value] = ' '.join(fragment)
                        else:
                            target.send(buses)
                            break
    except GeneratorExit:
        target.close()


@coroutine
def direction_filter(field, value, target):
    d = (yield)
    if d.get(field) == value:
        target.send(d)


@coroutine
def printbus():
    while True:
        bus = (yield)
        print "%(route)s,%(id)s,\"%(direction)s\"," \
              "%(latitude)s,%(longitude)s" % bus


if __name__ == '__main__':
    xml.sax.parse('bus.xml', Bushandler(buses_to_dict(cothread.threaded(direction_filter('route', '22', printbus())))))
Пример #6
0
from cothread import threaded, threaded_safe
from cobroadcast import broadcast
from copipe import grep
from cofollow import printer

p = printer()

target = broadcast([
    threaded(grep('foo', p)),
    threaded(grep('bar', p)),
])

# target = broadcast([
#     threaded_safe(grep('foo', p)),
#     threaded_safe(grep('bar', p)),
# ])

for i in range(100):
    target.send('foo is nice - %d' % i)
    target.send('bar is bad - %d' % i)

del p
del target