Skip to content
This repository was archived by the owner on Jul 14, 2020. It is now read-only.
This repository was archived by the owner on Jul 14, 2020. It is now read-only.

Multiprocessing may not be working properly #38

@AnotherKamila

Description

@AnotherKamila

People tried this code and it didn't work:

import pyscion as sci
import sys
import time
from multiprocessing import Process
import threading

MTU = 1300 # leave enough space for SCION headers

def send(destination, nbytes, p):
    with sci.connect(destination, p) as fd:
        print("Startsend")
        for i in range(int(nbytes/1000)+1):
            fd.write(MTU*b'a')
        print("Endsend")

def startProc(dest_addr, nbytes):
    print("hi")
    destination = "{}:12345".format(dest_addr)  # send to port 12345
    print(' === TASK to destination {} : {}MB ==='.format(destination, int(nbytes/1024/1024)))
    paths = really_get_paths(destination)
    print('Got %d paths' % len(paths))
    threads = []
    for p in paths:
        t = threading.Thread(target=send, args=(destination, nbytes, p))
        t.start()
        threads.append(t)

    time.sleep(120)
    [t.join() for t in threads]

def main():
    print("VERSION 12")
    sci.init()
    processes = []
    print('Local Address is {}'.format(sci.local_address()))
    i = 0
    for dest_addr, nbytes in parse_tasks_from_stdin():
        if i >= 2:
            break
        print("trying to start process {}, with bytes {}", dest_addr, nbytes)
        proc = Process(target=startProc, args=(dest_addr, nbytes,))
        print("process initilaized")
        proc.start()
        print("start process finished")
        processes.append(proc)
    i = i+1
    time.sleep(120)
    print("i finish")
    [p.join() for p in processes]

def really_get_paths(destination):
    # getting paths is async, so let's just retry until we get some
    while True:
        try:
            return sci.paths(destination)
        except sci.SCIONException:
            time.sleep(0.1)

def parse_tasks_from_stdin():
    def parse_line(line):
        dest, nbytes = line.split()
        return dest, int(nbytes)
    return [parse_line(line) for line in sys.stdin]

if __name__ == "__main__":
    main()

Metadata

Metadata

Assignees

No one assigned

    Labels

    APIPython API componentbugSomething isn't workinginfrastructure

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions