Questions

20 views
Skip to first unread message

Ram Rachum

unread,
Aug 7, 2014, 5:35:50 PM8/7/14
to python...@googlegroups.com
Hi,

I have a few questions about sarge. (Vinay - Sorry for emailing you questions personally before, I forgot there was a mailing list to this project.)

1. How do I stop/kill a sarge process?

2. When I terminate my Python process, the subprocess started by sarge remains alive. How do I cause it to be killed together with my process?

3. I want to run a process on Sarge, but I want the stderr to be filtered before it's displayed on stderr (i.e. to show only some lines.)

I figured I could simply create a file-like function/class that will be an argument to `sarge.run`, but... It wouldn't accept a function because it didn't have `fileno`. Fine. I made a class, make `fileno` raise OSError like it should when there isn't a file number. Nope, exception not handled. Finally I tried subclassing `Capture` and overriding the `write` method. Nope, that method isn't even called, and looking at the `Capture` code I can't even tell which code is invoked on write.


Thanks,
Ram.

Vinay Sajip

unread,
Aug 8, 2014, 7:34:19 AM8/8/14
to python...@googlegroups.com


1. How do I stop/kill a sarge process?

If you run a single command, a Command instance is created and returned, which you can call kill or terminate on (these methods wrap the subprocess.Popen versions).
If you run multiple commands, a Pipeline instance is created and returned, whose commands property returns a list of Command instances you can operate on.

2. When I terminate my Python process, the subprocess started by sarge remains alive. How do I cause it to be killed together with my process?
 
There's no difference between subprocesses started via sarge and those started via subprocess - to terminate them, use the information I gave above.

3. I want to run a process on Sarge, but I want the stderr to be filtered before it's displayed on stderr (i.e. to show only some lines.)

I figured I could simply create a file-like function/class that will be an argument to `sarge.run`, but... It wouldn't accept a function because it didn't have `fileno`. Fine. I made a class, make `fileno` raise OSError like it should when there isn't a file number. Nope, exception not handled. Finally I tried subclassing `Capture` and overriding the `write` method. Nope, that method isn't even called, and looking at the `Capture` code I can't even tell which code is invoked on write.
 
Either I'm misunderstanding what you're saying, or you're not quite understanding how subprocesses work. Subprocesses write to their output, but they are arbitrary programs, whose output you can't in general override. Sarge reads that output as input - so overriding write isn't going to do anything (Capture doesn't even define a write method).

Read the documentation in this section and subsequent sections for information relevant to processing output sent from a subprocess. Note particularly the information about buffering - things like this are hard to diagnose and get right without a good understanding of how subprocess streams work (not just at the sarge or Python level - sometimes you need to understand OS-level details).

Regards,

Vinay Sajip

Ram Rachum

unread,
Aug 10, 2014, 8:27:09 AM8/10/14
to python...@googlegroups.com
Thanks Vinay!


--
You received this message because you are subscribed to a topic in the Google Groups "sarge" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python-sarge/sTJuvncfBqg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python-sarge...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages