Skip to content

Commit

Permalink
Oddball typing fix: Scope of func causes warning for "put"
Browse files Browse the repository at this point in the history
I.e. because the input could be None
  • Loading branch information
mikenerone committed Jan 4, 2024
1 parent e00a81c commit 5a5d7f9
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions slurry/environments/_multiprocessing.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Implements a section that runs in an independent python proces."""

from multiprocessing import Process, SimpleQueue
from typing import Any, Iterable, Callable
from typing import Any, Iterable, Callable, cast

import trio

Expand Down Expand Up @@ -39,13 +39,15 @@ async def pump(self, input: Iterable[Any], output: Callable[[Any], None]):
process = Process(target=self._process_run_target,
args=(input_queue, output_queue))

async def sender():
async for item in input:
await trio.to_thread.run_sync(input_queue.put, (item,))
await trio.to_thread.run_sync(input_queue.put, ())

async with trio.open_nursery() as nursery:
if input:
input_queue = cast(SimpleQueue, input_queue)

async def sender():
async for item in input:
await trio.to_thread.run_sync(input_queue.put, (item,))
await trio.to_thread.run_sync(input_queue.put, ())

nursery.start_soon(sender)
process.start()
while True:
Expand Down

0 comments on commit 5a5d7f9

Please sign in to comment.