示例#1
0
def main():
    stage = mpipe.UnorderedStage(for_loop, 2)
    pipe = mpipe.Pipeline(stage)

    for foobar in range(5):
        pipe.put(int(sys.argv[1]) if len(sys.argv) >= 2 else 10)

    pipe.put(None)
示例#2
0
def main(watched_path, mountpoint, logfile="test_log.csv"):
    oh = OutputHandler.OutputHandler(logfile)

    def signal_handler(sig, frame):  # TODO maybe bug - needs two Ctrl+C to exit
        oh.close()

    signal.signal(signal.SIGINT, signal_handler)

    stage1 = mpipe.UnorderedStage(scanner.scan_file, size=3, max_backlog=3)
    stage2 = mpipe.OrderedStage(oh.write, size=1)
    pipeline = mpipe.Pipeline(stage1.link(stage2))

    watcher = Watcher(watched_path, pipeline)
    watcher.main([sys.argv[0], mountpoint], foreground=True)
示例#3
0
# Parse files in a pipeline.
def parseFile(fname):
    """Parse the XML file looking for fully demangled class
    names, and communicate the result."""
    names = list()
    doc = xml.dom.minidom.parse(fname)
    classes = doc.getElementsByTagName('Class')
    for entry in classes:
        name = entry.getAttribute('demangled')
        NSPACE = 'Wm5::'
        if name[:len(NSPACE)] != NSPACE:
            continue
        names.append(name)
    return names
pipe = mpipe.Pipeline(mpipe.UnorderedStage(parseFile, num_cpus))
for fname in fnames:
    pipe.put(fname)
pipe.put(None)

# Report on progress in realtime.
total_names = dict()
done_count = 0
for result in pipe.results():
    for name in result:
        total_names[name] = None
    done_count += 1
    percent = float(done_count) / len(fnames) * 100
    sys.stdout.write('\r' + '%d of %d (%.1f%%)'%(done_count, len(fnames), percent))
    sys.stdout.flush()
示例#4
0
pipe_iproc = mpipe.Pipeline(filter_detector)


# Create an auxiliary process (modeled as a one-task pipeline)
# that simply pulls results from the image processing pipeline,
# and deallocates associated shared memory after allowing
# the designated amount of time to pass.
def deallocate(tdelta):
    for tstamp in pipe_iproc.results():
        elapsed = datetime.datetime.now() - tstamp
        if tdelta - elapsed > datetime.timedelta():
            time.sleep(tdelta.total_seconds())
        del images[tstamp]


pipe_dealloc = mpipe.Pipeline(mpipe.UnorderedStage(deallocate))
pipe_dealloc.put(
    datetime.timedelta(microseconds=1e6))  # Start it up right away.

# Create the OpenCV video capture object.
cap = cv2.VideoCapture(DEVICE)
cap.set(3, WIDTH)
cap.set(4, HEIGHT)

# Run the video capture loop, allocating shared memory
# and feeding the image processing pipeline.
# Run for configured duration, or (if duration < 0) until we
# connect to socket (duration re-interpreted as port number.)
now = datetime.datetime.now()
end = now + datetime.timedelta(seconds=abs(DURATION))
while end > now or DURATION < 0:
示例#5
0
    'multiwork',
    'filter',
    )

# Export Dia diagrams.
saved = os.getcwd()
os.chdir('source')
def runDia(diagram):
    """Generate the diagrams using Dia."""
    ifname = '{}.dia'.format(diagram)
    ofname = '{}.png'.format(diagram)
    cmd = 'dia -t png-libart -e {} {}'.format(ofname, ifname)
    print('  {}'.format(cmd))
    subprocess.call(cmd, shell=True)
    return True
pipe = mpipe.Pipeline(mpipe.UnorderedStage(runDia, len(diagrams)))
for diagram in diagrams: 
    pipe.put(diagram)
pipe.put(None)
for result in pipe.results():
    pass
os.chdir(saved)

# Copy the .py examples from test/ to source/ directory
# so that they can be picked up by the Sphinx build.
codes = (
    'tiny.py',
    'helloworld.py',
    'chain.py',
    'pipeout.py',
    'fork.py',
示例#6
0
num_cpus = multiprocessing.cpu_count()
print('Running %d commands on %d CPUs' % (len(commands), num_cpus))


# Run commands in a pipeline.
def runCommand(command):
    """Run the given command in a subprocess shell."""
    result = subprocess.call(command,
                             shell=True,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.STDOUT)
    return result


pipe = mpipe.Pipeline(mpipe.UnorderedStage(runCommand, num_cpus))
for command in commands:
    if OPTS['verbose']:
        print(command)
    pipe.put(command)
pipe.put(None)

# Report on progress in realtime.
num_succeeded = 0
for result in pipe.results():

    num_succeeded += int(not result)
    percent = float(num_succeeded) / len(commands) * 100
    sys.stdout.write('\r' + '%d of %d (%.1f%%)' %
                     (num_succeeded, len(commands), percent))
    sys.stdout.flush()
示例#7
0
import sys
import mpipe


def forloop(amount):
    for ii in xrange(amount):
        pass


stage = mpipe.UnorderedStage(forloop, 2)
pipe = mpipe.Pipeline(stage)

for foobar in range(5):
    pipe.put(int(sys.argv[1]))

pipe.put(None)