Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'except:': 0.07; 'msg': 0.07; 'skip:/ 10': 0.07; 'try:': 0.07; "'w')": 0.09; 'slow.': 0.09; 'subject:into': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; 'weird': 0.15; 'above?': 0.16; 'data...': 0.16; 'fine.': 0.16; 'investigate': 0.16; 'line)': 0.16; 'subject:writing': 0.16; 'utc,': 0.16; 'write.': 0.16; 'wrote:': 0.17; 'bytes': 0.17; 'skip:" 30': 0.20; 'pipe': 0.22; 'cc:2**0': 0.23; 'monday,': 0.23; 'seems': 0.23; 'cc:no real name:2**0': 0.24; 'linux': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; '(which': 0.26; 'embedded': 0.27; 'translated': 0.27; "doesn't": 0.28; 'there.': 0.28; 'wrap': 0.29; "skip:' 10": 0.30; 'function': 0.30; 'code': 0.31; 'point': 0.31; 'could': 0.32; 'print': 0.32; 'surely': 0.33; 'problem': 0.33; 'everyone': 0.33; 'typically': 0.33; 'received:google.com': 0.34; 'thanks': 0.34; 'open': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'next': 0.35; 'but': 0.36; "i'll": 0.36; 'too': 0.36; 'itself': 0.37; 'quite': 0.37; 'received:209': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'sure': 0.38; 'your': 0.60; 'from:no real name:2**0': 0.60; 'email addr:gmail.com': 0.63; 'more': 0.63; 'else.': 0.65; 'receive': 0.71; '2013': 0.84; 'careless': 0.84; 'dongle': 0.84; 'lot,': 0.95 X-Received: by 10.49.63.164 with SMTP id h4mr1049140qes.39.1361275835906; Tue, 19 Feb 2013 04:10:35 -0800 (PST) Newsgroups: comp.lang.python Date: Tue, 19 Feb 2013 04:10:35 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=92.40.254.242; posting-account=EvoLHwoAAAAe6MGgc84vdAuhA1J1BvTN References: <76620a9e-45fe-499d-b1bf-06b1d2a91c25@googlegroups.com> User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 92.40.254.242 MIME-Version: 1.0 Subject: Re: improving performance of writing into a pipe From: mikprog@gmail.com To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=ISO-8859-1 Cc: python-list@python.org 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: , Message-ID: Lines: 79 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1361275844 news.xs4all.nl 6971 [2001:888:2000:d::a6]:43500 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:39210 On Monday, February 18, 2013 7:29:09 PM UTC, Serhiy Storchaka wrote: > On 18.02.13 17:12, mikprog@gmail.com wrote: > > > 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). > > > > def write_to_pipe(line): > > hexbytes = ''.join('\\x%02x' % ord(c) for c in line) > > with open('/tmp/mypipe', 'w') as f: > > f.write(hexbytes) I'll take your hexbytes = '' line (which is surely more efficient than mine). However whit this approach open + write it seems the pipe doesn't get the data... I am not sure what is going on. At this point I suspect it could be a problem on the pipe itself (which I inherited). It is just weird that the pipe accept this correctly: wrap = ["echo -en '", "' > /tmp/midi"] msg = hexbytes.join(wrap) os.popen( msg ) but seems to be careless of approach open + write. I need to investigate there. Thanks a lot, to you and to everyone else. Mik