王珂 | 1 Sep 2008 05:39
Picon

monitor subprocess and get it's output during execution

Hi,
 
I have a python program needs to do some download task from file server to local disk regularly.
I intend to call robocopy.exe (a download tool in windows) do the real download job.
 
--Below codes works:
DownloadArgs = " \\servername\Sourcepath d:\destinationPath *.bin"
os.system("robocopy.exe" +" "+ "DownloadArgs")
 
But the problem is :
1.Program halt until this robocopy download complete.
  As the download will last 2~3hours, I want to do and display something while downloading.
  Such as display a ">" each 10 seconds while downloading.
  
2.robocopy's output display in console.
  I want to hide robocopy's output, meanwhile get latest output each 10 secends then display only a portion of it.
 
--Then I use:
p = subprocess.Popen(["robocopy.exe" +" " + "DownloadArgs"],Shell = True,stdout = PIPE)
p.communicate()
 
This can hide robocopy's output, but still can't display the download process is going.
 
--Then I use:
print "Download begin ..."
p = subprocess.Popen(["robocopy.exe" +" " + "DownloadArgs"],Shell = True,stdout = PIPE)
while not str(p.poll()).isdigit():
    print ">",
    time.sleep(10)
    #don't know how to grab output and display portion of it
print "Download complete with retval (%d) "% (p.poll())
 
This will make robocopy never terminate, and display ">>>>>>" forever.
 
Any suggestion is welcome. Thanks in advance.
 
Regards,
Colin
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor
goldgod a | 1 Sep 2008 10:03
Picon

Tramline implementation


hi,
      I want to implement a tramline python library. I created a virtual host in apache  and created a python(cgi) file with simple uploading concepts.Tramline is not interacting with apache.  I tried get examples but they given  for plone and zope. Is any idea or examples available.

 
--
Thanks & Regards,
goldgod

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor
Kent Johnson | 1 Sep 2008 13:22
Gravatar

Re: Tramline implementation

On Mon, Sep 1, 2008 at 4:03 AM, goldgod a <agoldgod <at> gmail.com> wrote:
>
> hi,
>       I want to implement a tramline python library. I created a virtual
> host in apache  and created a python(cgi) file with simple uploading
> concepts.Tramline is not interacting with apache.  I tried get examples but
> they given  for plone and zope. Is any idea or examples available.

I'm not sure what your problem is. Do you mean that your cgi is never
being called by Apache? You have to configure apache for this to
happen. Check the Apache docs or google 'python cgi apache'

Kent
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Kent Johnson | 1 Sep 2008 13:30
Gravatar

Re: monitor subprocess and get it's output during execution

On Sun, Aug 31, 2008 at 11:39 PM, 王珂 <wkgogogo <at> gmail.com> wrote:

> --Then I use:
> print "Download begin ..."
> p = subprocess.Popen(["robocopy.exe" +" " + "DownloadArgs"],Shell =
> True,stdout = PIPE)
> while not str(p.poll()).isdigit():
>     print ">",
>     time.sleep(10)
>     #don't know how to grab output and display portion of it
> print "Download complete with retval (%d) "% (p.poll())
>
> This will make robocopy never terminate, and display ">>>>>>" forever.

I am not an expert in Popen, but I think in this example robocopy is
blocked trying to output. Here is how to read the robocopy output:

p = subprocess.Popen(["robocopy.exe" +" " + "DownloadArgs"],Shell =
True,stdout = PIPE)
while True:
  line = p.stdout.readline()
  if not line: break
  print line

Kent
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Richard Lovely | 1 Sep 2008 13:59
Gravatar

Concatenation vs formatting

Just a couple of quick questions:
What differences are there in efficency (i.e. time and memory) between
string concatenation ("foo" + "bar") and printf style formatting
("%s%s" % ("foo","bar")).
Is there any place where one is better than the other, and any places
where either should be avoided?  (I tend to program entirely using
formatting.)

Thanks
--

-- 
Richard "Roadie Rich" Lovely, part of the JNP|UK Famile
www.theJNP.com
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Wayne Watson | 1 Sep 2008 16:17
Picon
Favicon

How Compute # of Days between Two Dates?

That's the question in Subject. For example, the difference between 08/29/2008 and 09/03/2008 is +5. The difference between 02/28/2008 and 03/03/2008 is 4, leap year--extra day in Feb. I'm really only interested in years between, say, 1990 and 2050. In other words not some really strange period of time well outside our current era of history.
--
Signature.html Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39° 15' 7" N, 121° 2' 32" W, 2700 feet Interesting government experience prior to their presidency or bid for it:  Abraham Lincoln: 2 years; George Washington: 0 years; Dwight Eisenhower: 0 years; James Buchanan: 29 years* Barack Obama: 11 years; John McCain: 26 years * Not a particularly good president at all Web Page: <www.speckledwithstars.net/>
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor
William Allison | 1 Sep 2008 16:34
Picon

Re: How Compute # of Days between Two Dates?

Wayne Watson wrote:
> That's the question in Subject. For example, the difference between 08/29/2008 
> and 09/03/2008 is +5. The difference between 02/28/2008 and 03/03/2008 is 4, 
> leap year--extra day in Feb. I'm really only interested in years between, say, 
> 1990 and 2050. In other words not some really strange period of time well 
> outside our current era of history.

I've used the datetime module to do something similar.

Python 2.5.2 (r252:60911, Feb 22 2008, 07:57:53)
[GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> today = datetime.date.today()
>>> print today
2008-09-01
>>> last_year = datetime.date(2007, 9, 1)
>>> print today - last_year
366 days, 0:00:00
>>>

HTH,
Will

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

greg whittier | 1 Sep 2008 16:41

Re: How Compute # of Days between Two Dates?

On Mon, Sep 1, 2008 at 10:17 AM, Wayne Watson
<sierra_mtnview <at> sbcglobal.net> wrote:
> That's the question in Subject. For example, the difference between
> 08/29/2008 and 09/03/2008 is +5. The difference between 02/28/2008 and
> 03/03/2008 is 4, leap year--extra day in Feb. I'm really only interested in
> years between, say, 1990 and 2050. In other words not some really strange
> period of time well outside our current era of history.

You want the datetime module.

>>> from datetime import datetime
>>> datetime(2008,03,03) - datetime(2008,2,28)
datetime.timedelta(4)
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

bob gailer | 1 Sep 2008 19:51
Picon

Re: Concatenation vs formatting

Richard Lovely wrote:
> Just a couple of quick questions:
> What differences are there in efficency (i.e. time and memory) between
> string concatenation ("foo" + "bar") and printf style formatting
> ("%s%s" % ("foo","bar")).
> Is there any place where one is better than the othe
concatenation should be more efficient as formatting takes 4 more 
bytecodes than concatenation, one of which is binary_format which will 
take more execution time.

However unless your application does many of those it is not worth the 
effort to choose one over the other. I almost always favor formatting as 
it is so much easier to read, maintain and extend.

--

-- 
Bob Gailer
Chapel Hill NC 
919-636-4239

When we take the time to be aware of our feelings and 
needs we have more satisfying interatctions with others.

Nonviolent Communication provides tools for this awareness.

As a coach and trainer I can assist you in learning this process.

What is YOUR biggest relationship challenge?

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Wayne Watson | 2 Sep 2008 02:07
Picon
Favicon

Responding to Tutor Posts, Reply-To

When I reply to a response to my post, it seems to go back to the respondent. I'd like it to just go back to the list. I'm using Seamonkey (Mozilla). I can do a reply-all but that sends it to the respondent and the list. It seems as though other lists have a Reply-To, which sends the post to the list. Did I set something up wrong when I subscribed?

--
Signature.html Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39° 15' 7" N, 121° 2' 32" W, 2700 feet Interesting government experience prior to their presidency or bid for it:  Abraham Lincoln: 2 years; George Washington: 0 years; Dwight Eisenhower: 0 years; James Buchanan: 29 years* Barack Obama: 11 years; John McCain: 26 years * Not a particularly good president at all Web Page: <www.speckledwithstars.net/>
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Gmane