@@ -3,6 +3,7 @@ import { expose } from 'comlink';
3
3
import { loadPyodide , version } from 'pyodide' ;
4
4
import type { PyodideInterface } from 'pyodide' ;
5
5
import { Signal } from './standalone_signal' ;
6
+ import type { PyProxy } from 'pyodide/ffi' ;
6
7
const DEBUG = true ;
7
8
8
9
var pyodide : PyodideInterface ;
@@ -11,6 +12,8 @@ declare const REFL1D_WHEEL_FILE: string;
11
12
declare const BUMPS_WHEEL_FILE : string ;
12
13
declare const MOLGROUPS_WHEEL_FILE : string ;
13
14
15
+ type APIResult = PyProxy | number | string | boolean | null | undefined ;
16
+
14
17
async function loadPyodideAndPackages ( ) { // loads pyodide
15
18
pyodide = await loadPyodide ( {
16
19
indexURL : `https://cdn.jsdelivr.net/pyodide/v${ version } /full/`
@@ -23,8 +26,6 @@ async function loadPyodideAndPackages() { // loads pyodide
23
26
import micropip
24
27
await micropip.install([
25
28
"matplotlib",
26
- "plotly",
27
- "mpld3",
28
29
"periodictable",
29
30
"blinker",
30
31
"dill",
@@ -67,8 +68,12 @@ async function loadPyodideAndPackages() { // loads pyodide
67
68
problem = dill.loads(dilled_problem)
68
69
api.state.problem.fitProblem = problem
69
70
71
+ def get_nllf():
72
+ return api.state.problem.fitProblem.nllf()
73
+
70
74
wrapped_api["set_autosave_session_interval"] = expose(set_autosave_session_interval, "set_autosave_session_interval")
71
75
wrapped_api["set_problem"] = expose(set_problem, "set_problem")
76
+ wrapped_api["get_nllf"] = expose(get_nllf, "get_nllf")
72
77
73
78
def fit_progress_handler(event):
74
79
api.emit("evt_fit_progress", dill.dumps(event))
@@ -161,10 +166,10 @@ export class Server {
161
166
let r = await this . nativefs ?. syncfs ?.( ) ;
162
167
}
163
168
164
- async asyncEmit ( signal : string , ...args : unknown [ ] ) {
169
+ async asyncEmit ( signal : string , ...args : APIResult [ ] ) {
165
170
// this is for emit() calls from the python server
166
171
const js_args = args . map ( ( arg ) => {
167
- return arg ?. toJs ?.( { dict_converter : Object . fromEntries } ) ?? arg ;
172
+ return arg ?. toJs ?.( { dict_converter : Object . fromEntries , create_pyproxies : false } ) ?? arg ;
168
173
} ) ;
169
174
const handlers = this . handlers [ signal ] ?? [ ] ;
170
175
for ( let handler of handlers ) {
@@ -177,11 +182,12 @@ export class Server {
177
182
// (which might be another server)
178
183
const api = await pyodideReadyPromise ;
179
184
const callback = ( args [ args . length - 1 ] instanceof Function ) ? args . pop ( ) : null ;
180
- const result = await api . get ( signal ) ( args ) ;
181
- const jsResult = result ?. toJs ?.( { dict_converter : Object . fromEntries } ) ?? result ;
185
+ const result : PyProxy = await api . get ( signal ) ( args ) ;
186
+ const jsResult = result ?. toJs ?.( { dict_converter : Object . fromEntries , create_pyproxies : false } ) ?? result ;
182
187
if ( callback !== null ) {
183
188
await callback ( jsResult ) ;
184
189
}
190
+ result ?. destroy ?.( ) ;
185
191
return jsResult ;
186
192
}
187
193
0 commit comments