You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This function is called after the server's event loop is running.
87
+
"""
88
+
await asyncio.sleep(.1)
89
+
90
+
68
91
Making an extension discoverable
69
92
--------------------------------
70
93
@@ -117,6 +140,7 @@ An ExtensionApp:
117
140
- has an entrypoint, ``jupyter <name>``.
118
141
- can serve static content from the ``/static/<name>/`` endpoint.
119
142
- can add new endpoints to the Jupyter Server.
143
+
- can start asynchronous tasks after the server has started.
120
144
121
145
The basic structure of an ExtensionApp is shown below:
122
146
@@ -156,6 +180,11 @@ The basic structure of an ExtensionApp is shown below:
156
180
...
157
181
# Change the jinja templating environment
158
182
183
+
asyncdef_start_jupyter_server_extension(self):
184
+
...
185
+
# Extend this method to start any (e.g. async) tasks
186
+
# after the main Server's Event Loop is running.
187
+
159
188
asyncdefstop_extension(self):
160
189
...
161
190
# Perform any required shut down steps
@@ -171,6 +200,7 @@ Methods
171
200
* ``initialize_settings()``: adds custom settings to the Tornado Web Application.
172
201
* ``initialize_handlers()``: appends handlers to the Tornado Web Application.
173
202
* ``initialize_templates()``: initialize the templating engine (e.g. jinja2) for your frontend.
203
+
* ``_start_jupyter_server_extension()``: enables the extension to start (async) tasks _after_ the server's main Event Loop has started.
174
204
* ``stop_extension()``: called on server shut down.
175
205
176
206
Properties
@@ -320,6 +350,42 @@ pointing at the ``load_classic_server_extension`` method:
320
350
If the extension is enabled, the extension will be loaded when the server starts.
321
351
322
352
353
+
Starting asynchronous tasks from an ExtensionApp
354
+
------------------------------------------------
355
+
356
+
.. versionadded:: 2.15.0
357
+
358
+
359
+
An ``ExtensionApp`` can start asynchronous tasks after Jupyter Server's event loop is started by overriding its ``_start_jupyter_server_extension()`` method. This can be helpful for setting up e.g. background tasks.
0 commit comments