Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!multikabel.net!newsfeed20.multikabel.net!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'except:': 0.07; 'msg': 0.07; 'skip:/ 10': 0.07; 'try:': 0.07; 'python': 0.09; "'w')": 0.09; 'received:mail-vb0-f46.google.com': 0.09; 'slow.': 0.09; 'subject:into': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; 'above?': 0.16; 'cc:name:python list': 0.16; 'code?': 0.16; 'fine.': 0.16; 'guys,': 0.16; 'subject:writing': 0.16; 'wrote:': 0.17; 'bytes': 0.17; 'received:209.85.212.46': 0.18; 'skip:" 30': 0.20; 'pipe': 0.22; 'cc:2**0': 0.23; 'seems': 0.23; 'linux': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'embedded': 0.27; 'guess': 0.27; 'translated': 0.27; 'message- id:@mail.gmail.com': 0.27; 'received:209.85.212': 0.28; 'run': 0.28; 'wrap': 0.29; 'e.g.': 0.30; 'function': 0.30; 'code': 0.31; 'file': 0.32; 'print': 0.32; 'typically': 0.33; 'received:google.com': 0.34; 'open': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'next': 0.35; 'too': 0.36; 'quite': 0.37; 'received:209': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'sure': 0.38; 'more': 0.63; 'receive': 0.71; '2013': 0.84; 'dongle': 0.84; 'oscar': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=zUIo7H4G/WwotX/8aiS9408BciZGXs5qi0uRfS0n2I8=; b=JWG54SwEr2+AJdzHqctt6No1TrFrhEh2gjVBf+5rnt+6NNuYGB7mQ7oNKxz+uNePqB YzTN+xEKznw+VnbGiSGwuGhMIcVPivj9nsaQdNmh5pDTK/MT9K9yXbWwwa8vsB82CGZd tbarIpLnq8F4X95kG1ZcYnBGlgTdpP8qFnQ0mJxMVY+il9yEqk0eWBvmMiSieqXjeP35 tkI8Qf3IuCZkyjWIRRw5NWfVmlesrDU+2Oox4t9RL0LaPoMr5pNrGimqENtuRo27zWLl XMpygjwHCEU1pz3X6E1CN2redEfvEaF7lX+APHnNb+3Ba6sDPbxFqIIC+eijvUTp2RFp wY7Q== X-Received: by 10.220.149.11 with SMTP id r11mr15678426vcv.44.1361200933785; Mon, 18 Feb 2013 07:22:13 -0800 (PST) MIME-Version: 1.0 In-Reply-To: <76620a9e-45fe-499d-b1bf-06b1d2a91c25@googlegroups.com> References: <76620a9e-45fe-499d-b1bf-06b1d2a91c25@googlegroups.com> From: Oscar Benjamin Date: Mon, 18 Feb 2013 15:21:53 +0000 Subject: Re: improving performance of writing into a pipe To: mikprog@gmail.com Content-Type: text/plain; charset=ISO-8859-1 Cc: Python List X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 37 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1361200943 news.xs4all.nl 6902 [2001:888:2000:d::a6]:57066 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:39102 On 18 February 2013 15:12, wrote: > Hi guys, > > on an embedded linux system (BeagleBoard) I am writing data coming from bluetooth dongle into a pipe. > The function is the following one: > > > def write_to_pipe(line): > > # next line ensures that bytes like '0x09' are not translated into '\t' for > #example, and they are sent as such > hexbytes = "\\x" + "\\x".join([hex(ord(c))[2:].zfill(2) for c in line]) > wrap = ["echo -en '", "' > /tmp/mypipe"] > msg = hexbytes.join(wrap) > print "DBG: sending: ", msg > > try: > os.popen( msg ) > except: > print "Error: write_to_pipe has failed!" > > > Now I typically receive 4 bytes from the bluetooth dongle and that is fine. > However when I receive many more than that it seems that the writing into the pipe is too slow. > > Is there any clever/obvious way to improve the code above? > (I am quite sure there is to be honest). Can you not open the pipe file directly in Python code? e.g. fout = open('/tmp/mypipe', 'w') fout.write(data) I guess that this would be more efficient than using os.popen to run echo. Oscar