<jupyter_start><jupyter_text>`AsyncResult`-Objekt`apply()` gibt im `noblock`-Modus ein `AsyncResult`-Objekt zurück. Dieses erlaubt zu einem späteren Zeitpunkt Anfragen mit der `get()`-Methode zu den Ergebnissen. Überdies werden in diesem Objekt auch bei der Ausführung anfallende Metadaten gesammelt.Das [AsyncResult](https://ipyparallel.readthedocs.io/en/latest/reference/details.htmlasyncresults)-Objekt bietet eine Reihe praktischer Funktionen für die Parallelisierung, die über Pythons [multiprocessing.pool.AsyncResult](https://docs.python.org/3/library/multiprocessing.htmlmultiprocessing.pool.AsyncResult). hinausgehen:  `get_dict``AsyncResult.get_dict()`<jupyter_code>import os
import ipyparallel as ipp

rc = ipp.Client()
ar = rc[:].apply_async(os.getpid)
pids = ar.get_dict()
rc[:]['pid_map'] = pids<jupyter_output><empty_output><jupyter_text>Metadaten`Client.metadata`  Timing  Iterierbare Map-Ergebnisse<jupyter_code>from __future__ import print_function

import time

import ipyparallel as ipp

# create client & view
rc = ipp.Client()
dv = rc[:]
v = rc.load_balanced_view()

# scatter 'id', so id=0,1,2 on engines 0,1,2
dv.scatter('id', rc.ids, flatten=True)
print("Engine IDs: ", dv['id'])

# create a Reference to `id`. This will be a different value on each engine
ref = ipp.Reference('id')
print("sleeping for `id` seconds on each engine")
tic = time.time()
ar = dv.apply(time.sleep, ref)
for i,r in enumerate(ar):
    print("%i: %.3f"%(i, time.time()-tic))

def sleep_here(t):
    import time
    time.sleep(t)
    return id,t

# one call per task
print("running with one call per task")
amr = v.map(sleep_here, [.01*t for t in range(100)])
tic = time.time()
for i,r in enumerate(amr):
    print("task %i on engine %i: %.3f" % (i, r[0], time.time()-tic))

print("running with four calls per task")
# with chunksize, we can have four calls per task
amr = v.map(sleep_here, [.01*t for t in range(100)], chunksize=4)
tic = time.time()
for i,r in enumerate(amr):
    print("task %i on engine %i: %.3f" % (i, r[0], time.time()-tic))

print("running with two calls per task, with unordered results")
# We can even iterate through faster results first, with ordered=False
amr = v.map(sleep_here, [.01*t for t in range(100,0,-1)], ordered=False, chunksize=2)
tic = time.time()
for i,r in enumerate(amr):
    print("slept %.2fs on engine %i: %.3f" % (r[1], r[0], time.time()-tic))

from functools import reduce
from math import sqrt
import numpy as np

X = np.linspace(0,100)
add = lambda a,b: a+b
sq = lambda x: x*x
sqrt(reduce(add, map(sq, X)) / len(X))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14450867052023122, 'fraction_numerical': 0.015028901734104046, 'mean_word_length': 5.166270783847981, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '244955', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 982, 'n_tokens_neox': 955, 'n_words': 275, 'path': 'docs/refactoring/performance/ipyparallel/asyncresult.ipynb', 'repo_name': 'veit/jupyter-tutorial-de', 'size': '2595'}