Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #47329
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder7.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python@mrabarnett.plus.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.005 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'say,': 0.05; 'except:': 0.09; 'exception,': 0.09; 'snippet': 0.09; 'spelling': 0.09; 'try:': 0.09; 'python': 0.11; 'def': 0.12; '+data': 0.16; 'error).': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message- id:@mrabarnett.plus.com': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'subject:Problems': 0.16; 'subject:port': 0.16; 'sure.': 0.16; 'true:': 0.16; 'exception': 0.16; 'so.': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'seems': 0.21; 'programming': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'byte': 0.24; 'possibly': 0.26; 'this:': 0.26; 'pass': 0.26; 'code:': 0.26; 'header:In-Reply-To:1': 0.27; 'raise': 0.29; 'have,': 0.30; "i'm": 0.30; '(which': 0.31; 'went': 0.31; 'code': 0.31; 'catching': 0.31; 'skip:q 20': 0.31; 'time:': 0.31; 'class': 0.32; 'skip:d 20': 0.34; "i'd": 0.34; 'subject:with': 0.35; "can't": 0.35; 'except': 0.35; 'problem.': 0.35; 'skip:s 30': 0.35; 'received:84': 0.35; 'test': 0.35; 'but': 0.35; 'really': 0.36; 'false': 0.36; 'doing': 0.36; 'hi,': 0.36; 'problems': 0.38; 'to:addr:python-list': 0.38; 'bad': 0.39; 'to:addr:python.org': 0.39; 'even': 0.60; 'catch': 0.60; 'removing': 0.60; 'then,': 0.60; 'tell': 0.60; "you're": 0.61; 'first': 0.61; 'email addr:gmail.com': 0.63; 'due': 0.66; 'header:Reply-To:1': 0.67; 'reply-to:no real name:2**0': 0.71; 'serial': 0.72; 'bare': 0.84; 'preventing': 0.84; 'quote,': 0.84; 'reply-to:addr:python.org': 0.84; '2013': 0.98 |
| X-CM-Score | 0.00 |
| X-CNFS-Analysis | v=2.1 cv=RZapVTdv c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=oyR3mlnJdzkA:10 a=XECAlpdaJpMA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=gJ-ACk_o3E8A:10 a=pGLkceISAAAA:8 a=kGZ_-S9niXddrHUryEIA:9 a=wPNLvfGTeEIA:10 a=MSl-tDqOz04A:10 |
| X-AUTH | mrabarnett:2500 |
| Date | Fri, 07 Jun 2013 15:18:17 +0100 |
| From | MRAB <python@mrabarnett.plus.com> |
| User-Agent | Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130509 Thunderbird/17.0.6 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: Problems with serial port interface |
| References | <8cf25b92-f4c5-43ac-a285-240abc6ee3e7@googlegroups.com> <1f18bcf1-57b5-474a-b5d4-d5b51ef859c1@googlegroups.com> |
| In-Reply-To | <1f18bcf1-57b5-474a-b5d4-d5b51ef859c1@googlegroups.com> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 8bit |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| Reply-To | python-list@python.org |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2851.1370614704.3114.python-list@python.org> (permalink) |
| Lines | 75 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1370614704 news.xs4all.nl 15955 [2001:888:2000:d::a6]:53675 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:47329 |
Show key headers only | View raw
On 07/06/2013 11:17, lionelgreenstreet@gmail.com wrote:
> Sorry for my quote,
> but do you have any suggestion?
>
> Il giorno martedì 4 giugno 2013 23:25:21 UTC+2, lionelgr...@gmail.com ha scritto:
>> Hi,
>>
>> i'm programming in python for the first time: i want to create a serial port reader. I'm using python3.3 and pyQT4; i'm using also pyserial.
>>
>> Below a snippet of the code:
>>
>>
>> class CReader(QThread):
>> def start(self, ser, priority = QThread.InheritPriority):
>> self.ser = ser
>> QThread.start(self, priority)
>> self._isRunning = True
>> self.numData=0;
>>
>> def run(self):
>> print("Enter Creader")
>> while True:
>> if self._isRunning:
>> try:
>> data = self.ser.read(self.numData)
>> n = self.ser.inWaiting()
>> if n:
>> data = self.ser.read(n)
>> self.emit(SIGNAL("newData(QString)"), data.decode('cp1252', 'ignore'))
>> self.ser.flushInput()
>> except:
>> pass
>> else:
>> return
>>
>> def stop(self):
>> self._isRunning = False
>> self.wait()
>>
>> This code seems work well, but i have problems in this test case:
>>
>> +baud rate:19200
>> +8/n/1
>> +data transmitted: 1 byte every 5ms
>>
>> After 30seconds (more or less) the program crashes: seems a buffer problem, but i'm not really sure.
>>
>> What's wrong?
>>
Using a "bare except" like this:
try:
...
except:
...
is virtually always a bad idea. The only time I'd ever do that would
be, say, to catch something, print a message, and then re-raise it:
try:
...
except:
print("Something went wrong!")
raise
Even then, catching Exception would be better than a bare except. A
bare except will catch _every_ exception, including NameError (which
would mean that it can't find a name, possibly due to a spelling error).
A bare except with pass, like you have, is _never_ a good idea. Python
might be trying to complain about a problem, but you're preventing it
from doing so.
Try removing the try...except: pass and let Python tell you if it has a
problem.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Problems with serial port interface lionelgreenstreet@gmail.com - 2013-06-04 14:25 -0700
Re: Problems with serial port interface lionelgreenstreet@gmail.com - 2013-06-07 03:17 -0700
Re: Problems with serial port interface Peter Otten <__peter__@web.de> - 2013-06-07 13:23 +0200
Re: Problems with serial port interface MRAB <python@mrabarnett.plus.com> - 2013-06-07 15:18 +0100
Re: Problems with serial port interface lionelgreenstreet@gmail.com - 2013-06-08 11:15 -0700
Re: Problems with serial port interface lionelgreenstreet@gmail.com - 2013-06-12 01:39 -0700
Re: Problems with serial port interface lionelgreenstreet@gmail.com - 2013-06-13 01:01 -0700
csiph-web