Skip to content

Commit

Permalink
Merge pull request #188 from goodboy/we_aint_got_zombie_shields
Browse files Browse the repository at this point in the history
We aint got zombie shields
  • Loading branch information
goodboy authored Jan 18, 2021
2 parents 8fdab8e + 9f4e497 commit d8b6c00
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
45 changes: 45 additions & 0 deletions examples/multiple_streams_one_portal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import trio
import tractor


log = tractor.log.get_logger('multiportal')


async def stream_data(seed=10):
log.info("Starting stream task")

for i in range(seed):
yield i
await trio.sleep(0) # trigger scheduler


async def stream_from_portal(p, consumed):

async for item in await p.run(stream_data):
if item in consumed:
consumed.remove(item)
else:
consumed.append(item)


async def main():

async with tractor.open_nursery(loglevel='info') as an:

p = await an.start_actor('stream_boi', enable_modules=[__name__])

consumed = []

async with trio.open_nursery() as n:
for i in range(2):
n.start_soon(stream_from_portal, p, consumed)

# both streaming consumer tasks have completed and so we should
# have nothing in our list thanks to single threadedness
assert not consumed

await an.cancel()


if __name__ == '__main__':
trio.run(main)
8 changes: 6 additions & 2 deletions tractor/_spawn.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,14 @@ async def new_proc(
# ``trio.Process.__aexit__()`` (it tears down stdio
# which will kill any waiting remote pdb trace).

# TODO: No idea how we can enforce zombie
# reaping more stringently without the shield
# we used to have below...

# always "hard" join sub procs:
# no actor zombies allowed
with trio.CancelScope(shield=True):
await proc.wait()
# with trio.CancelScope(shield=True):
await proc.wait()
else:
# `multiprocessing`
assert _ctx
Expand Down

0 comments on commit d8b6c00

Please sign in to comment.