Path: csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'url:pypi': 0.03; '16,': 0.03; 'binary': 0.07; 'correct.': 0.07; 'alter': 0.09; 'okay': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'psf': 0.10; 'python': 0.11; 'suggest': 0.14; '2.7': 0.14; 'windows': 0.15; '480,': 0.16; 'ah,': 0.16; 'bugs.': 0.16; 'e.errno': 0.16; 'e[0]': 0.16; 'path:': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'subclass': 0.16; 'sudo': 0.16; 'typeerror:': 0.16; 'wrote:': 0.18; 'module': 0.19; 'version.': 0.19; '>>>': 0.22; 'install': 0.23; 'header:User- Agent:1': 0.23; 'faq': 0.24; 'instance,': 0.24; 'module,': 0.24; "shouldn't": 0.24; 'specify': 0.24; 'helpful': 0.24; 'mon,': 0.24; "haven't": 0.24; 'sort': 0.25; "i've": 0.25; 'handling': 0.26; 'header:X-Complaints-To:1': 0.27; 'correct': 0.29; 'chris': 0.29; 'points': 0.29; 'see,': 0.30; "i'm": 0.30; 'code': 0.31; 'getting': 0.31; 'comments': 0.31; "skip:' 10": 0.31; '>>>>': 0.31; 'index,': 0.31; 'minor': 0.31; 'file': 0.32; 'this.': 0.32; 'probably': 0.32; 'interface': 0.32; 'run': 0.32; 'another': 0.32; 'says': 0.33; 'url:python': 0.33; 'entirely': 0.33; 'older': 0.33; 'actual': 0.34; "i'd": 0.34; 'case,': 0.35; 'but': 0.35; 'there': 0.35; 'version': 0.36; 'raising': 0.36; 'set.': 0.36; 'skip:" 50': 0.36; "didn't": 0.36; 'web,': 0.36; 'thanks': 0.36; 'possible': 0.36; 'url:org': 0.36; 'should': 0.36; 'level': 0.37; 'system,': 0.38; 'confirmed': 0.38; 'nov': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'rather': 0.38; 'does': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'read': 0.60; 'then,': 0.60; 'worry': 0.60; 'no.': 0.61; "you're": 0.61; 'address': 0.63; 'name': 0.63; 'myself': 0.63; 'grab': 0.64; 'teaching': 0.64; 'more': 0.64; 'between': 0.67; 'yes': 0.68; 'results': 0.69; 'serial': 0.72; 'felt': 0.74; 'apt-get': 0.84; 'believe,': 0.84; 'conservative': 0.84; 'subject:system': 0.84; 'response,': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: Interrupted system call Date: Mon, 17 Nov 2014 09:55:23 +0100 Organization: None References: <54685C24.9040208@bellfamily.org.uk> <54697545.2030207@bellfamily.org.uk> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p57bd8ca6.dip0.t-ipconnect.de User-Agent: KNode/4.13.3 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: 97 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1416214539 news.xs4all.nl 2940 [2001:888:2000:d::a6]:39156 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:80968 Chris Angelico wrote: > On Mon, Nov 17, 2014 at 3:10 PM, Peter Bell > wrote: >> Many thanks for your helpful response, Chris. >> >> On 17/11/14 06:13, Chris Angelico wrote: >>> >>> On Sun, Nov 16, 2014 at 7:11 PM, Peter Bell >>> wrote: >>>> >>>> File "/usr/lib/python3.4/site-packages/serial/serialposix.py", line >>>> 480, >>>> in read >>>> if e[0] != errno.EAGAIN: >>>> TypeError: 'InterruptedError' object is not subscriptable >>>> ===================================================================== >>>> >>>> >>>> I'm not sure how to address the 'InterruptedError'. Can it/should it >>>> be >>>> masked at the user code level with a 'try:' block? Or is there another >>>> way >>>> to deal with it? >>> >>> >>> At this stage, you're not getting it, because of the cascaded error, >>> so that's the thing to deal with. >> >> >> Okay - I was just thinking that if the 'InterruptedError' didn't occur, >> then the 'TypeError' would never be exposed! > > Correct. The handling of InterruptedError (a subclass of OSError) is > what's raising TypeError. > >> Ah, I understand. I believe, then, that this is from the pyserial module, >> fetched from sourceforge. >> >> I see, now, that the sourceforge download does specify >> 'pyserial-2.7.tar.gz' >> and, yes, I'm working in Python 3. I see, from other comments around the >> web, that I'm not the only person to be attempting to use this module >> with 3. >> >> Given that pyserial is for 2.7, it is probably unreasonable to report >> errant behaviour when run on Python 3. > > Yes and no. It may be possible to alter the code to be 2/3 compatible; > for instance, if e.errno is used instead of e[0], it should work in > both 2.7 and 3.x. (I haven't confirmed this, though.) But keep > reading. > >> I'm teaching myself (and the kids, as I go) Python and felt, rightly or >> wrongly, that it would be better to start with Python 3, rather than >> learning the older Python 2.x. > > You felt rightly. All you need is... > >> Is there a better way to interface to a serial port from Python 3? I've >> found a reference in the PSF 3.3.6 FAQ which points to pyserial on >> sourceforge. > > ... a solution to this. I would suggest looking on PyPI, the Python > Package Index, to see what you can get for Python 3. In your case, you > may well be in luck: > > https://pypi.python.org/pypi/pyserial > > There's a version that claims to work with any Python version (though > there's some minor disagreement; the metadata says 2.3-2.7 and > 3.0-3.3, but the Windows binaries say 2.4-2.7 and 3.0-3.4). I suspect > the "2.7" in the name is actually the version of PySerial, and it's > coincidental that that happens also to be a Python version. > > Since you seem to be on a POSIX system, you shouldn't need to worry > about the provided binary installers. Use pip3 to install it for your > Python 3, and you should be all set. I'd suggest a more conservative path: if available install the version that comes with your distribution. $ sudo apt-get python3-serial might do the job. > Now, since the package does claim to support Python 3, any > discrepancies between that claim and the actual results you're seeing > *are* reportable bugs. But it's entirely possible that using pip to > install it will sort all that out, as it'll go and grab the correct > version. > > All the best! > > ChrisA