xonsh/slug

context issue

Closed this issue · 9 comments

mitnk commented

This is the code in current readme:

with ProcessGroup() as pg:
  pipe = mkpipe()
  spam = pg.process(['spam'], stdin=StdIn(), stdout=pipe.side_in, stderr=StdErr(), environ=...)
  eggs = pg.process(['eggs'], stdin=pipe.side_out, stdout=StdOut(), stderr=StdErr(), environ=...)
pg.start()
pg.join()

The last two line looks a bit weird. I mean it's valid but I'd like keep the pg only used inside the with block - make pg.start(), pg.join() implemented inside the context manager itself?

I'm currently debating on having the process group autostart when the context manager ends. It's convenient, but not really in flavor of the library (which I'm leaning in favor of primitives and explicit over implicit). Basically: This isn't a library to be friendly, this is a library to give you control of processes.

The .join() will very certainly be outside the block. We do not want to do that implicitly.

I like having the with block because it's visibly clear what chunk of code deals with setting up the process group. I plan on keeping the methods in place even if they're no-ops.

mitnk commented

Ok, understood. Yeah, it may be a better time to discuss API till the first works demo went out (like can run simple command like ls | less.

So I don't have process groups yet, but you can do:

p = Pipe()
ls = Process(['ls'], stdout=p.side_in)
less = Process(['less'], stdin=p.side_out)
ls.start()
less.start()
ls.join()
less.join()

and it'll run the pipeline and then wait for it to exit.

(Note: If you run this from an interactive prompt, potentially interesting things happen, depending on how much is pasted at once.)

mitnk commented

Yes, I know this. My previous comment was saying that when we could use slug to do this job - there's more than just run ls | less, it also includes things like controlling terminal manipulations etc.

Oh yeah, most of it hasn't been written. But you can now make usable pipelines, which might be close to what xonsh is doing right now.

I think next up is the Process Group, and then Psuedo Terminals. Both of which have some non-trivial features planned, but nothing impossible. I just got distracted by plumbing utilities.

mitnk commented

@astronouth7303 Ah, sorry, I mis-interpreted something above. The code looks good to me! I'll try this out.

Process Groups are done.

mitnk commented

Great! I'm closing this issue, since it's not related anymore.