MCPcopy
hub / github.com/pyodide/pyodide / test_nested_syncify

Function test_nested_syncify

src/tests/test_stack_switching.py:408–464  ·  view source on GitHub ↗
(selenium)

Source from the content-addressed store, hash-verified

406@requires_jspi
407@pytest.mark.requires_dynamic_linking
408def test_nested_syncify(selenium):
409 res = selenium.run_js(
410 """
411 async function f1() {
412 await sleep(30);
413 return await g1.callPromising();
414 }
415 async function f2() {
416 await sleep(30);
417 return await g2.callPromising();
418 }
419 async function getStuff() {
420 await sleep(30);
421 return "gotStuff";
422 }
423 pyodide.globals.set("f1", f1);
424 pyodide.globals.set("f2", f2);
425 pyodide.globals.set("getStuff", getStuff);
426
427 pyodide.runPython(`
428 from pyodide.ffi import run_sync
429 from js import sleep
430 def g():
431 run_sync(sleep(25))
432 return run_sync(f1())
433
434 def g1():
435 run_sync(sleep(25))
436 return run_sync(f2())
437
438 def g2():
439 run_sync(sleep(25))
440 return run_sync(getStuff())
441 `);
442 const l = pyodide.runPython("l = []; l")
443 const g = pyodide.globals.get("g");
444 const g1 = pyodide.globals.get("g1");
445 const g2 = pyodide.globals.get("g2");
446 const p = [];
447 p.push(g.callPromising().then((res) => l.append(res)));
448 p.push(pyodide.runPythonAsync(`
449 from js import sleep
450 for i in range(20):
451 run_sync(sleep(9))
452 l.append(i)
453 `));
454 await Promise.all(p);
455 const res = l.toJs();
456 for(let p of [l, g, g1, g2]) {
457 p.destroy()
458 }
459 return res;
460 """
461 )
462 assert "gotStuff" in res
463 del res[res.index("gotStuff")]
464 assert res == list(range(20))
465

Callers

nothing calls this directly

Calls 1

indexMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…