@@ -377,8 +377,16 @@ All in `PM/commonTest`, so they run wherever the interpreter loads.
377377 it on that loop, and Kotlin's completion resolves it via ` target_loop.call_soon_threadsafe(_pm_settle, ...) ` .
378378 The fast path (` PendingCall.isDone ` is ` true ` before ` deliver ` returns) never consults ` get_running_loop() `
379379 or the configured delivery loop and builds no ` Future ` .
380+ ** Resuming from a Kotlin/Native thread** (iOS and androidNative; #164 item 11, pythonx-concurrent S9.6;
381+ leader decision 2026-11-21, in 1.0, not owner-confirmed): any thread may resume a parked continuation,
382+ provided it holds ` withGIL ` while it resumes (` PendingCall ` 's contract, since the resumption runs the
383+ delivery listener inline): a bare ` pthread ` the runtime never attached, a Kotlin/Native ` Worker ` , or a
384+ ` kotlinx.coroutines ` dispatcher thread, which is a ` Worker ` underneath. The thread attaches on entry to
385+ the scope and is detached when it ends (depth back to 0); the sample's iOS section 7 does it with a
386+ ` Worker ` (` sample/src/iosMain/.../ProxyDemo.ios.kt ` ).
380387 ` Status: implemented ` on desktop and Kotlin/Native, ` PM/desktopTest/.../upcall/AsyncUpcallDeliveryTest.kt ` ,
381388 ` AsyncUpcallCancellationTest.kt ` , ` AsyncUpcallEarlyCancellationTest.kt ` , ` PM/nativeTest/.../AsyncUpcallNative*Test.kt ` ,
389+ ` PM/nativeTest/.../AsyncUpcallWorkerDeliveryTest.kt ` (the ` Worker ` rule),
382390 ` python-multiplatform-ksp/fixtures/app/.../GeneratedSuspendTest.kt ` ; ` planned ` on wasm (no threads).
383391- ** U-5a** (` suspend ` function-typed parameters, #164 item 7):
384392 An exposed Kotlin function, method or constructor may declare a top-level parameter of a ` suspend `
@@ -598,6 +606,58 @@ All in `PM/commonTest`, so they run wherever the interpreter loads.
598606 ` theContinuationIsDispatchedThroughTheCallersInterceptorNotRunOnTheLoopThread ` ,
599607 ` aKotlinxJobCancellationReachesTaskCancelThroughTheSubmitPrimitive ` ,
600608 ` aReceiverWithoutAwaitOrNoLoopFailsBeforeAnythingIsScheduled ` ).
609+ - ** U-5e** (stepping a Python coroutine from Kotlin, #164 item 13, pythonx-concurrent S7.9/S7.10/S7.13;
610+ fable-pmp's task 2026-11-21, agent proposal, not owner-confirmed):
611+ ` fun PyObject.step(value: PyObject? = null, context: PyObject? = null): PyStep ` and
612+ ` fun PyObject.throwInto(exception: PyObject, context: PyObject? = null): PyStep ` /
613+ ` throwInto(exception: Throwable, context) ` (package ` python.multiplatform.ffi.pythonx ` ) run ** one step** of
614+ the receiver, a coroutine, a generator or any object with the method used: ` receiver.send(value) ` (` None `
615+ when ` value ` is null) or ` receiver.throw(exception) ` , inside ` context.run(...) ` when a
616+ ` contextvars.Context ` is given, else in the calling thread's current context (a ` ContextVar.set ` inside
617+ the coroutine then stays in that thread's context). They need nothing but the interpreter: no binding
618+ module, no upcall table, no event loop; no loop is set running during a step (pythonx-concurrent §11
619+ item 6 is that library's decision).
620+ - ** One attachment, no suspension.** The whole step is one ` withGIL ` scope on the calling thread,
621+ whichever thread that is (a thread CPython never saw attaches for the call and is detached on return,
622+ the nesting depth back to what it was). The library code inside the scope contains no suspension point
623+ and runs no caller-supplied Kotlin code, so the GIL (attachment on 3.15t) is never held across a Kotlin
624+ suspension and on a JVM virtual thread the step is one pinned call (#161 ). A Python upcall into Kotlin
625+ from inside the coroutine runs under the step's frame as any upcall does.
626+ - ** The outcome is a sealed ` PyStep ` .** ` Yielded(value) ` : the object the coroutine suspended on (for an
627+ ` await ` of an ` asyncio ` future, the future itself; for U-5's proxies, the ` Future ` the binder handed
628+ out), a new owned reference the caller closes. ` Returned(value) ` : the coroutine returned; the
629+ ` StopIteration ` value, owned by the caller (` None ` for a bare return; an exhausted generator reports
630+ ` Returned(None) ` again, as its ` StopIteration ` does). ` Raised(exception) ` : the step raised, with the
631+ ` PyException ` (type, value, traceback, ` __context__ ` , ` __cause__ ` ) and the error indicator cleared;
632+ this includes ` RuntimeError("cannot reuse already awaited coroutine") ` for a finished coroutine,
633+ ` ValueError("coroutine already executing") ` for a step that overlaps another, and
634+ ` RuntimeError("cannot enter context: ... is already entered") ` when the given context is in use
635+ (the coroutine untouched in that case). A ` Raised ` whose ` exception.isCancelledError() ` is the
636+ cancellation signal; ` exception.toKotlinException() ` applies U-2's mapping.
637+ - ** Throwing in.** ` throwInto(PyObject) ` throws that exception instance (or class) into the coroutine at
638+ its suspension point. ` throwInto(Throwable) ` builds the Python exception with U-2's mapping: a Kotlin
639+ ` CancellationException ` arrives as ` asyncio.CancelledError ` with any Kotlin cause as ` __cause__ ` , a
640+ ` PyException ` as its original Python instance, any other throwable as ` RuntimeError(message) ` with
641+ the Kotlin cause chain on ` __cause__ ` .
642+ - ** Refusals before anything runs** (` IllegalArgumentException ` , the receiver untouched): a receiver
643+ without the method used (` send ` / ` throw ` ), a ` context ` that is not a ` contextvars.Context ` .
644+ - ** Threads.** Two steps of one coroutine never overlap: the driver sequences them (S7.11); each may
645+ run on a different thread, and ` threading.get_ident() ` inside the coroutine changes with the thread
646+ while ` contextvars ` stay with the ` Context ` the driver passes. Reference counting: the receiver and
647+ the arguments are the caller's and are not retained beyond the call; the bound method, the argument
648+ tuple and a ` StopIteration ` instance are released inside the scope; only the result is handed out.
649+ ` Status: implemented ` on desktop and Kotlin/Native (commonTest, so every target compiles and runs the
650+ thread-free part), ` PM/commonTest/.../pythonx/PyCoroutineStepTest.kt `
651+ (` aCoroutineIsSteppedWithSendValuesUntilItsReturnValueArrivesAndNothingLeaks ` ,
652+ ` eachStepRunsInsideTheGivenContextAndWritesStayInIt ` ,
653+ ` aKotlinThrowableThrownIntoTheCoroutineArrivesMappedAndTheOutcomeIsReported ` ,
654+ ` aFinishedCoroutineAnExhaustedGeneratorAndANonCoroutineAreReportedWithoutLeavingAnErrorIndicator ` ),
655+ ` PM/desktopTest/.../pythonx/PyCoroutineStepThreadTest.kt `
656+ (` eachStepMayRunOnADifferentThreadCPythonNeverSawAndLeavesItDetached ` ,
657+ ` aStepOnAVirtualThreadCompletesAndLeavesTheCarrierDetached ` ),
658+ ` PM/nativeTest/.../pythonx/PyCoroutineStepNativeTest.kt `
659+ (` aStepFromAThreadTheRuntimeNeverAttachedCompletesTheCoroutine ` ); ` planned ` on wasm for the thread
660+ claims only (no threads there; the commonTest part runs).
601661- ** U-6** Upcalls work in a GraalVM native image (desktop). ` Status: implemented ` with manual
602662 verification, procedure and record in ` docs/platforms/graal-native-image-verification.md `
603663 (` :sample:nativeCompile ` , Liberica NIK), guarded automatically by ` ReachabilityMetadataTest.kt ` (C-2).
0 commit comments