1"""The IPython ZMQ-based parallel computing interface."""
2
3# Copyright (c) IPython Development Team.
4# Distributed under the terms of the Modified BSD License.
5# export return_when constants
6import os
7from concurrent.futures import ALL_COMPLETED # noqa
8from concurrent.futures import FIRST_COMPLETED # noqa
9from concurrent.futures import FIRST_EXCEPTION # noqa
10
11from traitlets.config.configurable import MultipleInstanceError
12
13from ._version import __version__ # noqa
14from ._version import version_info # noqa
15from .client.asyncresult import * # noqa
16from .client.client import Client # noqa
17from .client.remotefunction import * # noqa
18from .client.view import * # noqa
19from .cluster import Cluster # noqa
20from .cluster import ClusterManager # noqa
21from .controller.dependency import * # noqa
22from .error import * # noqa
23from .serialize import * # noqa
24from .util import interactive # noqa
25
26# -----------------------------------------------------------------------------
27# Functions
28# -----------------------------------------------------------------------------
29
30
31def bind_kernel(**kwargs):
32 """Bind an Engine's Kernel to be used as a full IPython kernel.
33
34 This allows a running Engine to be used simultaneously as a full IPython kernel
35 with the QtConsole or other frontends.
36
37 This function returns immediately.
38 """
39 from ipykernel.kernelapp import IPKernelApp
40
41 from ipyparallel.engine.app import IPEngine
42
43 if IPEngine.initialized():
44 try:
45 app = IPEngine.instance()
46 except MultipleInstanceError:
47 pass
48 else:
49 return app.bind_kernel(**kwargs)
50
51 raise RuntimeError("bind_kernel must be called from an IPEngine instance")
52
53
54def register_joblib_backend(name='ipyparallel', make_default=False):
55 """Register the default ipyparallel backend for joblib."""
56 from .joblib import register
57
58 return register(name=name, make_default=make_default)
59
60
61# nbextension installation (requires notebook ≥ 4.2)
62def _jupyter_server_extension_paths():
63 return [{'module': 'ipyparallel'}]
64
65
66def _jupyter_nbextension_paths():
67 return [
68 {
69 'section': 'tree',
70 'src': 'nbextension/static',
71 'dest': 'ipyparallel',
72 'require': 'ipyparallel/main',
73 }
74 ]
75
76
77def _jupyter_labextension_paths():
78 return [
79 {
80 "src": "labextension",
81 "dest": "ipyparallel-labextension",
82 }
83 ]
84
85
86def _load_jupyter_server_extension(app):
87 """Load the server extension"""
88 # localte the appropriate APIHandler base class before importing our handler classes
89 from .nbextension.base import get_api_handler
90
91 get_api_handler(app)
92
93 from .nbextension.handlers import load_jupyter_server_extension
94
95 return load_jupyter_server_extension(app)
96
97
98# backward-compat
99load_jupyter_server_extension = _load_jupyter_server_extension
100
101_NONINTERACTIVE = os.getenv("IPP_NONINTERACTIVE", "") not in {"", "0"}