コード例 #1
0
ファイル: except_example.py プロジェクト: SemanticBeeng/scoop
def func2(n):
    if n > 10:
        # This exception is treated in func1
        raise Exception(10)
    launches = []
    for i in range(n):
        launches.append(futures.submit(func3, i + 1))
    result = futures.as_completed(launches)
    return sum(res.result() for res in result)
コード例 #2
0
def func2(n):
    if n > 10:
        # This exception is treated in func1
        raise Exception(10)
    launches = []
    for i in range(n):
        launches.append(futures.submit(func3, i + 1))
    result = futures.as_completed(launches)
    return sum(res.result() for res in result)
コード例 #3
0
ファイル: callback.py プロジェクト: SemanticBeeng/scoop
def main():
    # Create launches
    launches = [futures.submit(myFunc, i + 1) for i in range(5)]

    # Add a callback on every launches
    for launch in launches:
        launch.add_done_callback(doneElement)

    # Wait for the launches to complete.
    [completed for completed in futures.as_completed(launches)]
コード例 #4
0
def main():
    # Create launches
    launches = [futures.submit(myFunc, i + 1) for i in range(5)]

    # Add a callback on every launches
    for launch in launches:
        launch.add_done_callback(doneElement)

    # Wait for the launches to complete.
    [completed for completed in futures.as_completed(launches)]
コード例 #5
0
def run(values, parameters):
    # Create launches

    launches = [futures.submit(func, values, parameters, i) for i in cycle]
    # Add a callback on every launches
    for launch in launches:
        launch.add_done_callback(doneElement)

    # Wait for the launches to complete.
    [completed for completed in futures.as_completed(launches)]
コード例 #6
0
ファイル: scooptest.py プロジェクト: Mariovr/RG
def func2(n):
  launches = [futures.submit(func3, i + 1) for i in range(n)]
  # Spawn a generator for each completion, unordered
  result = (a.result() for a in futures.as_completed(launches))
  return sum(result)
コード例 #7
0
ファイル: tests.py プロジェクト: M-Abdulaziz81/neuronunit
def func2(n):
    launches = []
    for i in range(n):
        launches.append(futures.submit(func3, i + 1))
    result = futures.as_completed(launches)
    return sum(r.result() for r in result)
コード例 #8
0
ファイル: url_fetch_doc.py プロジェクト: wvangeit/scoop
import time


def getSize(string):
    """ This functions opens a web sites and then calculate the total
    size of the page in bytes. This is for the sake of the example. Do
    not use this technique in real code as it is not a very bright way
    to do this."""
    try:
        # We open the web page
        with urllib.request.urlopen(string, None, 1) as f:
            return sum(len(line) for line in f)
    except (urllib.error.URLError, socket.timeout) as e:
        return 0


if __name__ == "__main__":
    # The pageurl variable contains a link to a list of web sites. It is
    # commented for security's sake.
    pageurl = "http://httparchive.org/lists/Fortune%20500.txt"
    #pageurl  = "http://www.example.com"
    with urllib.request.urlopen(pageurl) as pagelist:
        pages = [page.decode() for page in pagelist][:30]

    # This will apply the getSize function on every item of the pages list
    # in parallel. The results will be treated as they are produced.
    fut = [futures.submit(getSize, page) for page in pages]
    for f in futures.as_completed(fut):
        time.sleep(0.1)  # Work on the data
        print(f.result())
コード例 #9
0
ファイル: tests.py プロジェクト: SmokinCaterpillar/scoop
def func2(n):
    launches = []
    for i in range(n):
        launches.append(futures.submit(func3, i + 1))
    result = futures.as_completed(launches)
    return sum(r.result() for r in result)
コード例 #10
0
def func2(n):
    launches = [futures.submit(func3, i + 1) for i in range(n)]
    # Spawn a generator for each completion, unordered
    result = (a.result() for a in futures.as_completed(launches))
    return sum(result)
コード例 #11
0
ファイル: url_fetch_doc.py プロジェクト: SemanticBeeng/scoop
from scoop import futures
import socket
import time

def getSize(string):
    """ This functions opens a web sites and then calculate the total
    size of the page in bytes. This is for the sake of the example. Do
    not use this technique in real code as it is not a very bright way
    to do this."""
    try:
        # We open the web page
        with urllib.request.urlopen(string, None, 1) as f:
            return sum(len(line) for line in f)
    except (urllib.error.URLError, socket.timeout) as e:
        return 0

if __name__ == "__main__":
    # The pageurl variable contains a link to a list of web sites. It is
    # commented for security's sake.
    pageurl = "http://httparchive.org/lists/Fortune%20500.txt"
    #pageurl  = "http://www.example.com"
    with urllib.request.urlopen(pageurl) as pagelist:
        pages = [page.decode() for page in pagelist][:30]

    # This will apply the getSize function on every item of the pages list
    # in parallel. The results will be treated as they are produced.
    fut = [futures.submit(getSize, page) for page in pages]
    for f in futures.as_completed(fut):
        time.sleep(0.1) # Work on the data
        print(f.result())