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

Toplevel await #25

Merged
merged 1 commit into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ jobs:
with:
activate-environment: xeus-python-kernel
environment-file: environment.yml
python-version: "3.10"
mamba-version: "*"
python-version: '3.10'
mamba-version: '*'

- name: Make sure the Mamba Python API is available
run: |
Expand Down Expand Up @@ -153,8 +153,8 @@ jobs:
with:
activate-environment: xeus-python-kernel
environment-file: environment.yml
python-version: "3.10"
mamba-version: "*"
python-version: '3.10'
mamba-version: '*'

- name: Install
run: pip install jupyterlite-xeus-python.tar.gz
Expand All @@ -177,7 +177,7 @@ jobs:
- name: Install mamba
uses: mamba-org/provision-with-micromamba@main
with:
micromamba-version: "0.22.0"
micromamba-version: '0.22.0'
environment-file: environment.yml
environment-name: xeus-python-kernel

Expand All @@ -204,7 +204,7 @@ jobs:
with:
activate-environment: xeus-python-kernel
environment-file: environment.yml
python-version: "3.10"
python-version: '3.10'

- name: Install
run: pip install jupyterlite-xeus-python.tar.gz
Expand Down
27 changes: 15 additions & 12 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,28 @@
## v0.2.0

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

- Add docs by @martinRenou in https://github.com/jupyterlite/xeus-python-kernel/pull/4
- Fix build by @martinRenou in https://github.com/jupyterlite/xeus-python-kernel/pull/5
- Add Matplotlib to the env by @martinRenou in https://github.com/jupyterlite/xeus-python-kernel/pull/7
- Do not use xeus-python's master branch by @martinRenou in https://github.com/jupyterlite/xeus-python-kernel/pull/8
- Simplify dockerfile by @martinRenou in https://github.com/jupyterlite/xeus-python-kernel/pull/9
- Xeus python build addon by @martinRenou in https://github.com/jupyterlite/xeus-python-kernel/pull/10

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

## v0.1.0

### Contributions
* Initial version by @DerThorsten in https://github.com/jupyterlite/xeus-python-kernel/commit/d28dbc1ec9c1dca3f861d79ee5930054c00d5998
* 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
* Fix README by @martinRenou in https://github.com/jupyterlite/xeus-python-kernel/pull/2
* Add Docker build by @martinRenou in https://github.com/jupyterlite/xeus-python-kernel/pull/3

- Initial version by @DerThorsten in https://github.com/jupyterlite/xeus-python-kernel/commit/d28dbc1ec9c1dca3f861d79ee5930054c00d5998
- 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
- Fix README by @martinRenou in https://github.com/jupyterlite/xeus-python-kernel/pull/2
- Add Docker build by @martinRenou in https://github.com/jupyterlite/xeus-python-kernel/pull/3

### Contributors
* @DerThorsten started the project
* @martinRenou made their first contribution in https://github.com/jupyterlite/xeus-python-kernel/pull/1

- @DerThorsten started the project
- @martinRenou made their first contribution in https://github.com/jupyterlite/xeus-python-kernel/pull/1

**Full Changelog**: https://github.com/jupyterlite/xeus-python-kernel/commits/0.1.0
8 changes: 4 additions & 4 deletions docs/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dependencies:
# - empack

- pip:
- jupyterlite
- jupyterlite-sphinx
- jupyterlite-xeus-python==0.3.0
- empack
- jupyterlite
- jupyterlite-sphinx
- jupyterlite-xeus-python==0.3.0
- empack
6 changes: 3 additions & 3 deletions docs/jupyterlite_config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"XeusPythonEnv": {
"packages": ["numpy", "matplotlib", "ipyleaflet"]
}
"XeusPythonEnv": {
"packages": ["numpy", "matplotlib", "ipyleaflet"]
}
}
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ dependencies:
- emsdk >=3.1.11
- empack >=0.5.3
- pip:
- jupyterlite
- jupyterlite
21 changes: 21 additions & 0 deletions src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ declare function createXeusModule(options: any): any;

globalThis.Module = {};

// when a toplevel cell uses an await, the cell is implicitly
// wrapped in a async function. Since the webloop - eventloop
// implementation does not support `eventloop.run_until_complete(f)`
// we need to convert the toplevel future in a javascript Promise
// this `toplevel` promise is then awaited before we
// execute the next cell. After the promise is awaited we need
// to do some cleanup and delete the python proxy
// (ie a js-wrapped python object) to avoid memory leaks
globalThis.toplevel_promise = null;
globalThis.toplevel_promise_py_proxy = null;

// We alias self to ctx and give it our newly created type
const ctx: Worker = self as any;
let raw_xkernel: any;
Expand Down Expand Up @@ -61,6 +72,16 @@ const loadCppModulePromise = load();
ctx.onmessage = async (event: MessageEvent): Promise<void> => {
await loadCppModulePromise;

if (
globalThis.toplevel_promise !== null &&
globalThis.toplevel_promise_py_proxy !== null
) {
await globalThis.toplevel_promise;
globalThis.toplevel_promise_py_proxy.delete();
globalThis.toplevel_promise_py_proxy = null;
globalThis.toplevel_promise = null;
}

const data = event.data;
const msg = data.msg;
const msg_type = msg.header.msg_type;
Expand Down