Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 6th, 2003, 06:16 AM
telex4's Avatar
telex4 telex4 is offline
Wacky hack
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2001
Location: London, England
Posts: 513 telex4 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 38 m 37 sec
Reputation Power: 13
Closing pipes

I've got a bit of code that opens a new pipe with popen, to start mencoder. When I call the close() function on it, it takes an unacceptably long time to close the pipe and return to the main thread.

Are there any better ways of handling external commands?

Reply With Quote
  #2  
Old March 6th, 2003, 08:40 AM
telex4's Avatar
telex4 telex4 is offline
Wacky hack
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2001
Location: London, England
Posts: 513 telex4 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 38 m 37 sec
Reputation Power: 13
Oh, I found out myself, so if anyone wants to know:

os.popen will wait for the process to finish before it actually closes the pipe and returns the result to you, which is why it takes so long. popen2.popen2 won't however, so I've just used the popen2 module and it now works fine.

Reply With Quote
  #3  
Old March 14th, 2003, 09:34 AM
telex4's Avatar
telex4 telex4 is offline
Wacky hack
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2001
Location: London, England
Posts: 513 telex4 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 38 m 37 sec
Reputation Power: 13
I thought I had this problem cracked, but it seems not! I now use the following code:

To open the pipe:
(self.pipe, self.junk) = popen2.popen2(command)

To close the pipe:
self.pipe.close()

Now when I close it, Python releases the pipe immediately, but it seems to just disconnect itself from the process and leave it running,which is of no use whatsoever! using sys.popen() and the associated close() methods worked OK, but very very slowly when closing. popen2.popen2 works more quickly, but it doesn't close the process.

How can I actually close the process, and do it quickly? Or will I just have to put up with zero responsiveness for a while waiting for the pipe to close properly?

Reply With Quote
  #4  
Old March 26th, 2003, 11:04 AM
kace kace is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Location: Atlanta
Posts: 9 kace User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 35 m
Reputation Power: 0
Interesting problem. I'd suggest a two pronged approach. First, if the sub-process is dragging on too long, why not just kill it? ( Popen3 and Popen4 have a pid method. )

Second of all, maybe it would be quicker (after having killed the sub-process) to just loop through and discard the unwanted data than it would be to close a "full" pipe.

Reply With Quote
  #5  
Old March 26th, 2003, 11:22 AM
telex4's Avatar
telex4 telex4 is offline
Wacky hack
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2001
Location: London, England
Posts: 513 telex4 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 38 m 37 sec
Reputation Power: 13
Yes, I ended up implementing it with Popen3, taking the pid and killing it, then clearing the zombie with waitpid(). I was thinking of making quite a complicated but more robust system with forks and exec() but I never got round to it, as Popen3 seems to work fine

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Closing pipes

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap