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

Commit 8dd0f30

Browse files
authored
Merge pull request #25 from DerThorsten/toplevel_await
Toplevel await
2 parents b5b64da + 4c9ed5b commit 8dd0f30

File tree

6 files changed

+50
-26
lines changed

6 files changed

+50
-26
lines changed

.github/workflows/build.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ jobs:
122122
with:
123123
activate-environment: xeus-python-kernel
124124
environment-file: environment.yml
125-
python-version: "3.10"
126-
mamba-version: "*"
125+
python-version: '3.10'
126+
mamba-version: '*'
127127

128128
- name: Make sure the Mamba Python API is available
129129
run: |
@@ -153,8 +153,8 @@ jobs:
153153
with:
154154
activate-environment: xeus-python-kernel
155155
environment-file: environment.yml
156-
python-version: "3.10"
157-
mamba-version: "*"
156+
python-version: '3.10'
157+
mamba-version: '*'
158158

159159
- name: Install
160160
run: pip install jupyterlite-xeus-python.tar.gz
@@ -177,7 +177,7 @@ jobs:
177177
- name: Install mamba
178178
uses: mamba-org/provision-with-micromamba@main
179179
with:
180-
micromamba-version: "0.22.0"
180+
micromamba-version: '0.22.0'
181181
environment-file: environment.yml
182182
environment-name: xeus-python-kernel
183183

@@ -204,7 +204,7 @@ jobs:
204204
with:
205205
activate-environment: xeus-python-kernel
206206
environment-file: environment.yml
207-
python-version: "3.10"
207+
python-version: '3.10'
208208

209209
- name: Install
210210
run: pip install jupyterlite-xeus-python.tar.gz

CHANGELOG.md

+15-12
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,28 @@
2525
## v0.2.0
2626

2727
### What's Changed
28-
* Add docs by @martinRenou in https://github.com/jupyterlite/xeus-python-kernel/pull/4
29-
* Fix build by @martinRenou in https://github.com/jupyterlite/xeus-python-kernel/pull/5
30-
* Add Matplotlib to the env by @martinRenou in https://github.com/jupyterlite/xeus-python-kernel/pull/7
31-
* Do not use xeus-python's master branch by @martinRenou in https://github.com/jupyterlite/xeus-python-kernel/pull/8
32-
* Simplify dockerfile by @martinRenou in https://github.com/jupyterlite/xeus-python-kernel/pull/9
33-
* Xeus python build addon by @martinRenou in https://github.com/jupyterlite/xeus-python-kernel/pull/10
28+
29+
- Add docs by @martinRenou in https://github.com/jupyterlite/xeus-python-kernel/pull/4
30+
- Fix build by @martinRenou in https://github.com/jupyterlite/xeus-python-kernel/pull/5
31+
- Add Matplotlib to the env by @martinRenou in https://github.com/jupyterlite/xeus-python-kernel/pull/7
32+
- Do not use xeus-python's master branch by @martinRenou in https://github.com/jupyterlite/xeus-python-kernel/pull/8
33+
- Simplify dockerfile by @martinRenou in https://github.com/jupyterlite/xeus-python-kernel/pull/9
34+
- Xeus python build addon by @martinRenou in https://github.com/jupyterlite/xeus-python-kernel/pull/10
3435

3536
**Full Changelog**: https://github.com/jupyterlite/xeus-python-kernel/compare/0.1.0...0.2.0
3637

3738
## v0.1.0
3839

3940
### Contributions
40-
* Initial version by @DerThorsten in https://github.com/jupyterlite/xeus-python-kernel/commit/d28dbc1ec9c1dca3f861d79ee5930054c00d5998
41-
* Remove sleep + renames according to https://github.com/jupyter-xeus/xeus-python/pull/530 by @martinRenou in https://github.com/jupyterlite/xeus-python-kernel/pull/1
42-
* Fix README by @martinRenou in https://github.com/jupyterlite/xeus-python-kernel/pull/2
43-
* Add Docker build by @martinRenou in https://github.com/jupyterlite/xeus-python-kernel/pull/3
41+
42+
- Initial version by @DerThorsten in https://github.com/jupyterlite/xeus-python-kernel/commit/d28dbc1ec9c1dca3f861d79ee5930054c00d5998
43+
- Remove sleep + renames according to https://github.com/jupyter-xeus/xeus-python/pull/530 by @martinRenou in https://github.com/jupyterlite/xeus-python-kernel/pull/1
44+
- Fix README by @martinRenou in https://github.com/jupyterlite/xeus-python-kernel/pull/2
45+
- Add Docker build by @martinRenou in https://github.com/jupyterlite/xeus-python-kernel/pull/3
4446

4547
### Contributors
46-
* @DerThorsten started the project
47-
* @martinRenou made their first contribution in https://github.com/jupyterlite/xeus-python-kernel/pull/1
48+
49+
- @DerThorsten started the project
50+
- @martinRenou made their first contribution in https://github.com/jupyterlite/xeus-python-kernel/pull/1
4851

4952
**Full Changelog**: https://github.com/jupyterlite/xeus-python-kernel/commits/0.1.0

docs/environment.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ dependencies:
1010
# - empack
1111

1212
- pip:
13-
- jupyterlite
14-
- jupyterlite-sphinx
15-
- jupyterlite-xeus-python==0.3.0
16-
- empack
13+
- jupyterlite
14+
- jupyterlite-sphinx
15+
- jupyterlite-xeus-python==0.3.0
16+
- empack

docs/jupyterlite_config.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"XeusPythonEnv": {
3-
"packages": ["numpy", "matplotlib", "ipyleaflet"]
4-
}
2+
"XeusPythonEnv": {
3+
"packages": ["numpy", "matplotlib", "ipyleaflet"]
4+
}
55
}

environment.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ dependencies:
88
- emsdk >=3.1.11
99
- empack >=0.5.3
1010
- pip:
11-
- jupyterlite
11+
- jupyterlite

src/worker.ts

+21
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@ declare function createXeusModule(options: any): any;
66

77
globalThis.Module = {};
88

9+
// when a toplevel cell uses an await, the cell is implicitly
10+
// wrapped in a async function. Since the webloop - eventloop
11+
// implementation does not support `eventloop.run_until_complete(f)`
12+
// we need to convert the toplevel future in a javascript Promise
13+
// this `toplevel` promise is then awaited before we
14+
// execute the next cell. After the promise is awaited we need
15+
// to do some cleanup and delete the python proxy
16+
// (ie a js-wrapped python object) to avoid memory leaks
17+
globalThis.toplevel_promise = null;
18+
globalThis.toplevel_promise_py_proxy = null;
19+
920
// We alias self to ctx and give it our newly created type
1021
const ctx: Worker = self as any;
1122
let raw_xkernel: any;
@@ -61,6 +72,16 @@ const loadCppModulePromise = load();
6172
ctx.onmessage = async (event: MessageEvent): Promise<void> => {
6273
await loadCppModulePromise;
6374

75+
if (
76+
globalThis.toplevel_promise !== null &&
77+
globalThis.toplevel_promise_py_proxy !== null
78+
) {
79+
await globalThis.toplevel_promise;
80+
globalThis.toplevel_promise_py_proxy.delete();
81+
globalThis.toplevel_promise_py_proxy = null;
82+
globalThis.toplevel_promise = null;
83+
}
84+
6485
const data = event.data;
6586
const msg = data.msg;
6687
const msg_type = msg.header.msg_type;

0 commit comments

Comments
 (0)