Example #1
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (c) 2018 John Markus Bjørndalen, [email protected].
# See LICENSE.txt for licensing details (MIT License).

from common import handle_common_args
from apycsp import process, Channel, chan_poisoncheck, poisonChannel, run_CSP
from apycsp.plugNplay import Identity

handle_common_args()

if 'BlackHoleChannel' not in vars():
    print("Temp workaround for missing BlackHoleChannel")

    class BlackHoleChannel(Channel):
        def __init__(self, name=None):
            Channel.__init__(self, name)

        @chan_poisoncheck
        async def _write(self, obj=None):
            pass

        @chan_poisoncheck
        async def _read(self):
            raise "BlackHoleChannels are not readable"


@process
async def PoisonTest(cout):
    for i in range(100):
        print(i)
Example #2
0
#!/usr/bin/env python3

import common
import apycsp
import apycsp.net
import asyncio
import time

args = common.handle_common_args([
    (("-s", "--serv"), dict(help="specify server as host:port (use multiple times for multiple servers)", action="append", default=[]))
])
if len(args.serv) < 1:
    apycsp.net.setup_client()
else:
    for sp in args.serv:
        apycsp.net.setup_client(sp)

loop = asyncio.get_event_loop()
apycsp.net.send_message_sync({'op' : 'ping'})
apycsp.net.send_message_sync({'op' : 'print', 'args' : 'foo\nbar'})


@apycsp.process
async def reader(ch):
    for i in range(10):
        print("About to read")
        ret = await ch.read()
        print(" - got message", ret)

rchan = apycsp.net.get_channel_proxy_s('net_t1')
Example #3
0
#!/usr/bin/env python3
import asyncio
import common
import apycsp
import apycsp.net
from apycsp import Channel

# Very simple server that only hosts the channels. The CSP processes run in the client(s)

args = common.handle_common_args([
    (("-p", "--port"), dict(help="specify port number (alternatively host:port) to bind server to", action="store", default="8890"))
])

loop = asyncio.get_event_loop()
serv = apycsp.net.start_server(args.port)


def serve_test():
    chnames = ['a', 'b', 'c', 'd']
    chans = [Channel(n) for n in chnames]
    for c in chans:
        apycsp.net.register_channel(c, c.name)
    # loop.create_task(writer(ch1))
    # loop.create_task(silent_writer(ch2))


serve_test()

try:
    loop.run_forever()
except KeyboardInterrupt:
Example #4
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Copyright (c) 2018 John Markus Bjørndalen, [email protected].
See LICENSE.txt for licensing details (MIT License).
"""
import time
from common import handle_common_args, avg
import apycsp
from apycsp import process, run_CSP

args = handle_common_args()

# NB: necessary to support the channel patching we're doing in common/common_exp
Channel = apycsp.Channel
print("Running with channel type", Channel)


@process
async def writer(N, cout):
    for i in range(N):
        await cout(i)


@process
async def reader(N, cin):
    for _ in range(N):
        await cin()


@process
Example #5
0
# https://github.com/kevin-chalmers/cpp-csp/blob/master/demos/stressedalt.cpp
# https://www.researchgate.net/publication/315053019_Development_and_Evaluation_of_a_Modern_CCSP_Library

import asyncio
import time
import common
import apycsp
from apycsp import process, Alternative, Channel, run_CSP

N_RUNS = 10
N_SELECTS = 10000
N_CHANNELS = 10
N_PROCS_PER_CHAN = 1000

print("--------------------- Stressed Alt --------------------")
common.handle_common_args()


@process
async def stressed_writer(cout, writer_id):
    "Stressed alt writer"
    while True:
        await cout(writer_id)


@process
async def stressed_reader(channels, writers_per_chan):
    print("Waiting 5 seconds for all writers to get going")
    await asyncio.sleep(5)
    print("- sleep done, reader ready")
Example #6
0
#!/usr/bin/env python3
# -*- coding: latin-1 -*-
from common import *
import apycsp
import os
import psutil
import sys
import time
import common
from apycsp import One2OneChannel, Any2OneChannel, One2AnyChannel, process, run_CSP

args = common.handle_common_args([
    (["np"], dict(type=int, help='number of procs', default=10, nargs="?")),
])

N_PROCS = args.np  # 10 if len(sys.argv) < 2 else int(sys.argv[1])


@process
async def simple_proc(pid, checkin, cin):
    # check in
    await checkin(pid)
    # wait for poison
    while True:
        x = await cin()


@process
async def killer(chin, pch, nprocs):
    global rss
    print("Killer waiting for the other procs to call in")