[Tutor] Understand subprocess poll
jarod_v6 at libero.it
jarod_v6 at libero.it
Tue Sep 9 16:36:47 CEST 2014
Thanks for yhe help!
The comand run is this
the class created are this:
def run(cmd,pi):
import subprocess
import time
import logging
logging.basicConfig(level=logging.DEBUG,format="%(asctime)s - %(name)s - %
(levelname)s - %(messag
e)s")
#logging.debug(" Running pipelines: %s" % (cmd))
# setup logging
log_file = "None"
tou = "file"+"_.log.txt"
if log_file is not None:
logfh = open(tou, "w")
else:
logfh = None
print "####################################################"
p1 = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE,stderr=logfh,
cwd=pi)
#logging.info(" Running pipelines: %s" % (cmd))
while True:
if p1.poll() is None:
time.sleep(3)
pass
if p1.poll()==0:
print 'Finish this step.'
logging.info("###################: %s %s" % (cmd,time.ctime()))
break
if p1.poll() is not None and p1.poll() != 0:
raise Exception('Not working please check the error')
# end logging
if logfh is not None:
logfh.close()
return 0
step_2_out =["~/software/STAR_2.3.0e.Linux_x86_64_static/STAR --genomeDir
/home/sbsuser/d
atabases/Starhg19/GenomeDir/ --runMode alignReads --readFilesIn %s %s --
runThreadN 12 --readFilesCommand zcat
"%(dx,sn)]
The problems is the script end the process but not allign all the data. If I
use the comand line the same code the process work.
How can resolve this issue?
>----Messaggio originale----
>Da: tutor-request at python.org
>Data: 09/09/2014 16.02
>A: <tutor at python.org>
>Ogg: Tutor Digest, Vol 127, Issue 26
>
>Send Tutor mailing list submissions to
> tutor at python.org
>
>To subscribe or unsubscribe via the World Wide Web, visit
> https://mail.python.org/mailman/listinfo/tutor
>or, via email, send a message with subject or body 'help' to
> tutor-request at python.org
>
>You can reach the person managing the list at
> tutor-owner at python.org
>
>When replying, please edit your Subject line so it is more specific
>than "Re: Contents of Tutor digest..."
>
>
>Today's Topics:
>
> 1. Re: Good approach regarding classes attributes (Sydney Shall)
> 2. Re: Good approach regarding classes attributes (leam hall)
> 3. Re: Understand subprocess poll (Wolfgang Maier)
> 4. Re: Good approach regarding classes attributes (Peter Otten)
> 5. Re: Good approach regarding classes attributes (Juan Christian)
> 6. Re: Good approach regarding classes attributes (Sydney Shall)
>
>
>----------------------------------------------------------------------
>
>Message: 1
>Date: Tue, 09 Sep 2014 15:09:32 +0200
>From: Sydney Shall <s.shall at virginmedia.com>
>To: tutor at python.org
>Subject: Re: [Tutor] Good approach regarding classes attributes
>Message-ID: <540EFC0C.3000202 at virginmedia.com>
>Content-Type: text/plain; charset="windows-1252"; Format="flowed"
>
>On 08/09/2014 18:39, Alan Gauld wrote:
>> On 08/09/14 15:17, Juan Christian wrote:
>>
>> One tiny tweak...
>>
>>> class User():
>>
>> You don't need the parens after User. You don;t have any superclasses
>> so they do nothing. Python convention for an empty parent list is just
>> to leave the parens off:
>>
>> class User:
>>
>A simple question from a newbie, in response to this surprise.
>Is it not helpful to always put (object) as the parent, if the class is
>not itself a sub-class?
>And while I am writing, what does OP stand for in this list?
>
>
>--
>Sydney Shall
>-------------- next part --------------
>An HTML attachment was scrubbed...
>URL: <http://mail.python.
org/pipermail/tutor/attachments/20140909/ebcdb792/attachment-0001.html>
>
>------------------------------
>
>Message: 2
>Date: Tue, 9 Sep 2014 09:14:39 -0400
>From: leam hall <leamhall at gmail.com>
>To: tutor <tutor at python.org>
>Subject: Re: [Tutor] Good approach regarding classes attributes
>Message-ID:
> <CACv9p5qq=PSmxPaYTZ3iCrgnWb3B8aWBV1X_WAHYfC=OA6+THA at mail.gmail.com>
>Content-Type: text/plain; charset=UTF-8
>
>On Tue, Sep 9, 2014 at 9:09 AM, Sydney Shall <s.shall at virginmedia.com> wrote:
>
>> And while I am writing, what does OP stand for in this list?
>
>"Original Poster". So I understand. Won't answer the Python question
>since I'm a newbie here myself.
>
>--
>Mind on a Mission
>
>
>------------------------------
>
>Message: 3
>Date: Tue, 09 Sep 2014 15:05:11 +0200
>From: Wolfgang Maier <wolfgang.maier at biologie.uni-freiburg.de>
>To: tutor at python.org
>Subject: Re: [Tutor] Understand subprocess poll
>Message-ID: <540EFB07.5050901 at biologie.uni-freiburg.de>
>Content-Type: text/plain; charset=utf-8; format=flowed
>
>On 09/09/2014 11:45 AM, Peter Otten wrote:
>> jarod_v6 at libero.it wrote:
>>
>>> I want to use subprocess for run some programs But I need to be sure the
>>> program end before continue with the other:
>>>
>>> subprocess.call("ls")
>>> cmd1 = i
>>> p1 = subprocess.Popen(cmd1,shell=True,stdout=subprocess.PIPE)
>>>
>>> while True:
>>> if p1.poll() is None:
>>> time.sleep(3)
>>>
>>> pass
>>> if p1.poll()==0:
>>> print '#'
>>> break
>>> if p1.poll() is not None and p1.poll() != 0:
>>> raise Exception('Error building Alignment using star with hg19
>>> database')
>>
>>> This are not working. How can I do?
>>> thanks in advance for the precious help
>>> bw,
>>
>> I don't understand why you would need this loop. Why don't you use
>> subprocess.call() and be done?
>>
>
>The OP is piping the process stdout so I assume he is going to read from
>it in place of the pass in his example.
>Since the subprocess is doing genome-wide sequence alignment (at least I
>guess so from the exception string) there will be lots of output, which
>would cause subprocess.call() to block.
>
>Assuming that the posted code was indented correctly and was otherwise
>run as posted this could also be the answer to the original question:
>you have to keep on consuming data from the pipe or its buffer is going
>to fill up and block everyhing. With a simple pass statement you do not
>achieve anything that you can't do with call.
>
>Wolfgang
>
>
>
>------------------------------
>
>Message: 4
>Date: Tue, 09 Sep 2014 15:44:22 +0200
>From: Peter Otten <__peter__ at web.de>
>To: tutor at python.org
>Subject: Re: [Tutor] Good approach regarding classes attributes
>Message-ID: <lun07o$e8n$1 at ger.gmane.org>
>Content-Type: text/plain; charset="ISO-8859-1"
>
>Sydney Shall wrote:
>
>> On 08/09/2014 18:39, Alan Gauld wrote:
>>> On 08/09/14 15:17, Juan Christian wrote:
>>>
>>> One tiny tweak...
>>>
>>>> class User():
>>>
>>> You don't need the parens after User. You don;t have any superclasses
>>> so they do nothing. Python convention for an empty parent list is just
>>> to leave the parens off:
>>>
>>> class User:
>>>
>> A simple question from a newbie, in response to this surprise.
>> Is it not helpful to always put (object) as the parent, if the class is
>> not itself a sub-class?
>
>The answer differs between Python 2 and 3. In Python 3
>
>class C: # preferred in Python 3
> pass
>
>and
>
>class C(object):
> pass
>
>are the same, so there is no point adding the explicit object inheritance.
>
>In Python 2 however
>
>class C:
> pass
>
>will create a "classic class" whereas
>
>class C(object): # preferred in Python 2
> pass
>
>is a "newstyle class". The most notable difference between these is that
>properties work correctly only with newstyle classes. Therefore making all
>your classes "newstyle" is a good idea.
>
>> And while I am writing, what does OP stand for in this list?
>
>Original Poster, as Leam says.
>
>
>
>
>------------------------------
>
>Message: 5
>Date: Tue, 9 Sep 2014 10:54:22 -0300
>From: Juan Christian <juan0christian at gmail.com>
>Cc: "tutor at python.org" <tutor at python.org>
>Subject: Re: [Tutor] Good approach regarding classes attributes
>Message-ID:
> <CAAp0bGvBVZD3OGSv4dE7q4J4YYSd1WKrXFbSovNrg-3xyFGWKA at mail.gmail.com>
>Content-Type: text/plain; charset="utf-8"
>
>On Mon, Sep 8, 2014 at 5:58 AM, Peter Otten <__peter__ at web.de <javascript:;>>
>wrote:
>
>>
>> PS: This is not about being pythonic, but it might be more convenient for
>> client code if you use datetime objects instead of timestamps:
>>
>> >>> import datetime
>> >>> last_logoff = datetime.datetime.utcfromtimestamp(1410065399)
>> >>> print(last_logoff)
>> 2014-09-07 04:49:59
>>
>
>Yes, I'll do it for sure, the API response is indeed returned that way to
>make things easier.
>-------------- next part --------------
>An HTML attachment was scrubbed...
>URL: <http://mail.python.
org/pipermail/tutor/attachments/20140909/aacbe49f/attachment-0001.html>
>
>------------------------------
>
>Message: 6
>Date: Tue, 09 Sep 2014 16:02:01 +0200
>From: Sydney Shall <s.shall at virginmedia.com>
>To: tutor at python.org
>Subject: Re: [Tutor] Good approach regarding classes attributes
>Message-ID: <540F0859.5070802 at virginmedia.com>
>Content-Type: text/plain; charset="windows-1252"; Format="flowed"
>
>On 09/09/2014 15:44, Peter Otten wrote:
>> Sydney Shall wrote:
>>
>>> On 08/09/2014 18:39, Alan Gauld wrote:
>>>> On 08/09/14 15:17, Juan Christian wrote:
>>>>
>>>> One tiny tweak...
>>>>
>>>>> class User():
>>>> You don't need the parens after User. You don;t have any superclasses
>>>> so they do nothing. Python convention for an empty parent list is just
>>>> to leave the parens off:
>>>>
>>>> class User:
>>>>
>>> A simple question from a newbie, in response to this surprise.
>>> Is it not helpful to always put (object) as the parent, if the class is
>>> not itself a sub-class?
>> The answer differs between Python 2 and 3. In Python 3
>>
>> class C: # preferred in Python 3
>> pass
>>
>> and
>>
>> class C(object):
>> pass
>>
>> are the same, so there is no point adding the explicit object inheritance.
>>
>> In Python 2 however
>>
>> class C:
>> pass
>>
>> will create a "classic class" whereas
>>
>> class C(object): # preferred in Python 2
>> pass
>>
>> is a "newstyle class". The most notable difference between these is that
>> properties work correctly only with newstyle classes. Therefore making all
>> your classes "newstyle" is a good idea.
>>
>>> And while I am writing, what does OP stand for in this list?
>> Original Poster, as Leam says.
>>
>>
>> _______________________________________________
>> Tutor maillist - Tutor at python.org
>> To unsubscribe or change subscription options:
>> https://mail.python.org/mailman/listinfo/tutor
>>
>Thanks Peter, most helpful.
>I was taught with Python 2.7, so now I understand the advice.
>
>
>--
>Sydney Shall
>-------------- next part --------------
>An HTML attachment was scrubbed...
>URL: <http://mail.python.
org/pipermail/tutor/attachments/20140909/502cb8e0/attachment.html>
>
>------------------------------
>
>Subject: Digest Footer
>
>_______________________________________________
>Tutor maillist - Tutor at python.org
>https://mail.python.org/mailman/listinfo/tutor
>
>
>------------------------------
>
>End of Tutor Digest, Vol 127, Issue 26
>**************************************
>
More information about the Tutor
mailing list