koil 3.3.2__tar.gz → 3.3.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: koil
3
- Version: 3.3.2
3
+ Version: 3.3.4
4
4
  Summary: Async for a sync world
5
5
  Author-email: jhnnsrs <jhnnsrs@gmail.com>
6
6
  License-Expression: MIT
@@ -214,10 +214,12 @@ class qt_to_async(QtCore.QObject, Generic[T, P]):
214
214
  qtfuture, args, kwargs, ctx = typed_tuple
215
215
 
216
216
  try:
217
- for ctx, value in ctx.items():
218
- ctx.set(value)
219
-
220
- self.coro(qtfuture, *args, **kwargs) # type: ignore
217
+ # ``ctx.run`` rather than setting each var: this runs on the Qt main
218
+ # thread, which outlives every call on it. Bare ``.set()`` left the
219
+ # caller's values there forever, so the next slot -- belonging to
220
+ # another caller, or to none -- read whatever the last one happened
221
+ # to leave behind.
222
+ ctx.run(self.coro, qtfuture, *args, **kwargs) # type: ignore
221
223
 
222
224
  except Exception as e:
223
225
  logger.error(
@@ -238,8 +240,8 @@ class qt_to_async(QtCore.QObject, Generic[T, P]):
238
240
  else:
239
241
  context, x = await qtfuture.aiofuture
240
242
 
241
- for ctx, value in context.items():
242
- ctx.set(value)
243
+ for var, value in context.items():
244
+ var.set(value)
243
245
 
244
246
  return x
245
247
 
@@ -278,10 +280,9 @@ class qt_gen_to_async_gen(QtCore.QObject, Generic[T, P]):
278
280
  qtgenerator, args, kwargs, ctx = typed_tuple
279
281
 
280
282
  try:
281
- for ctx, value in ctx.items():
282
- ctx.set(value)
283
-
284
- self.coro(qtgenerator, *args, **kwargs) # type: ignore
283
+ # Scoped to the call, not left on the Qt main thread -- see
284
+ # ``qt_to_async.on_called``.
285
+ ctx.run(self.coro, qtgenerator, *args, **kwargs) # type: ignore
285
286
 
286
287
  except Exception as e:
287
288
  logger.error(
@@ -304,8 +305,8 @@ class qt_gen_to_async_gen(QtCore.QObject, Generic[T, P]):
304
305
  else:
305
306
  context, result = await qtgenerator.nextfuture
306
307
 
307
- for ctx, value in context.items():
308
- ctx.set(value)
308
+ for var, value in context.items():
309
+ var.set(value)
309
310
 
310
311
  yield result
311
312
 
@@ -349,9 +350,10 @@ class async_to_qt(QtCore.QObject, Generic[T, P]):
349
350
  def on_returnedwithoutcontext(self, answer: Tuple[T, contextvars.Context]):
350
351
  res, ctxs = answer
351
352
 
352
- for ctx, value in ctxs.items():
353
- ctx.set(value)
354
- self.returned.emit(res)
353
+ # The coroutine's context is made visible to whoever handles `returned`,
354
+ # and then unwound. Setting it on the Qt main thread instead would leave
355
+ # it there for every later slot -- the thread outlives the call.
356
+ ctxs.run(self.returned.emit, res)
355
357
 
356
358
  def run(self, *args: P.args, **kwargs: P.kwargs) -> KoilFuture[T]:
357
359
  koil_loop = get_koiled_loop_or_raise()
@@ -415,10 +417,8 @@ class async_gen_to_qt(QtCore.QObject, Generic[T, P]):
415
417
  def on_yieldedwithoutcontext(self, answer: Tuple[T, contextvars.Context]):
416
418
  res, ctxs = answer
417
419
 
418
- for ctx, value in ctxs.items():
419
- ctx.set(value)
420
-
421
- self.yielded.emit(res)
420
+ # Scoped to the emit -- see `async_to_qt.on_returnedwithoutcontext`.
421
+ ctxs.run(self.yielded.emit, res)
422
422
 
423
423
  def run(self, *args: P.args, **kwargs: P.kwargs) -> KoilFuture[None]:
424
424
  koil_loop = get_koiled_loop_or_raise()
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "koil"
3
- version = "3.3.2"
3
+ version = "3.3.4"
4
4
  description = "Async for a sync world"
5
5
  authors = [{ name = "jhnnsrs", email = "jhnnsrs@gmail.com" }]
6
6
  requires-python = ">=3.11"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes