(selenium)
| 145 | |
| 146 | @run_in_pyodide |
| 147 | def test_pyproxy_refcount(selenium): |
| 148 | from pyodide.code import run_js |
| 149 | |
| 150 | run_js( |
| 151 | """ |
| 152 | function getRefCount(){ |
| 153 | return pyodide.runPython("sys.getrefcount(pyfunc)"); |
| 154 | } |
| 155 | self.jsfunc = function (f) { f(); }; |
| 156 | pyodide.runPython(` |
| 157 | import sys |
| 158 | from js import jsfunc |
| 159 | |
| 160 | def pyfunc(*args, **kwargs): |
| 161 | print(*args, **kwargs) |
| 162 | `); |
| 163 | |
| 164 | // the refcount should be 2 because: |
| 165 | // 1. pyfunc exists |
| 166 | // 2. pyfunc is referenced from the sys.getrefcount()-test below |
| 167 | // |
| 168 | // Each time jsfunc is called a new PyProxy to pyfunc is created. That |
| 169 | // PyProxy is destroyed when the call finishes, so the calls to |
| 170 | // jsfunc(pyfunc) do not change the reference count. |
| 171 | |
| 172 | assert(() => getRefCount() === 2); |
| 173 | |
| 174 | pyodide.runPython(` |
| 175 | jsfunc(pyfunc) |
| 176 | `); |
| 177 | |
| 178 | assert(() => getRefCount() === 2); |
| 179 | |
| 180 | pyodide.runPython(` |
| 181 | jsfunc(pyfunc) |
| 182 | jsfunc(pyfunc) |
| 183 | `) |
| 184 | assert(() => getRefCount() === 2); |
| 185 | pyodide.runPython(`del jsfunc`) |
| 186 | """ |
| 187 | ) |
| 188 | |
| 189 | |
| 190 | @run_in_pyodide |
nothing calls this directly
no test coverage detected
searching dependent graphs…