Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7636529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:42:18+00:00 2026-05-31T07:42:18+00:00

import serial ser = serial.Serial(‘COM5’, baudrate=9600, parity=serial.PARITY_NONE, timeout=1) print connected to: + ser.portstr while

  • 0
import serial

ser = serial.Serial('COM5', baudrate=9600, parity=serial.PARITY_NONE, timeout=1)
print "connected to: " + ser.portstr
while ser.isOpen():
    line = ser.readline().strip()
    if len(line)==16:
        print "Id number is",line[5:-2]

ser.close()

I’m using Pyserial to connect to an ID card reader and would like to have continuous polling. If I print everything, I notice that each timeout causes the readline to store an empty string. The above code ameliorates the problem of an ugly/infinite output, but I’m worried about memory usage. Since I’m reusing “line”, I presume there’s no issue there, but is there a problem with unlimited polling to begin with?

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T07:42:19+00:00Added an answer on May 31, 2026 at 7:42 am

    It looks fine – you should not waste memory in that loop, as it does not keep references to past lines.

    Setting a watch on the process to see whether memory consumption is growing over a day or two would not hurt you – but I’d not worry.

    Let’s suppose you are running this on an old machinne with 512MB RAM, and only 200MB left for the Python process – and that the timeout to readline takes one second, and that each empty string object takes up some 64 bytes in memory – you would be out of RAM in about 37 days.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using this script: import serial ser = serial.Serial('/dev/ttyUSB0') print 'Running..' while True: a=ser.read()
import serial import imaplib from time import sleep IMAP_SERVER='imap.gmail.com' IMAP_PORT=993 ser= serial.Serial ('/dev/ttyACM0',9600) M
import serial import imaplib from time import sleep IMAP_SERVER='imap.gmail.com' IMAP_PORT=993 ser= serial.Serial ('/dev/ttyACM0',9600) while
import java.lang.Math; public class NewtonIteration { public static void main(String[] args) { System.out.print(rootNofX(2,9)); }
import threading event = threading.Event() event.set() print event.wait(1) None event.clear() print event.wait(1) None So
import math def p(n): return 393000*((288200/393000)^n * math.exp(-(288200/393000)))/math.factorial(n) print p(3) When I run it,
import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; @SuppressWarnings(serial) public class Main extends JFrame
import org.jsoup.Jsoup; @SuppressWarnings({ unused, serial }) public class SimpleWebCrawler extends JFrame implements ActionListener {
import sys words = { 1 : 'one', 2 : 'two', 3 : 'three',
import sys sys.path.append('/home/myuser/svn-repos/myproject') from myproject.settings import * But, it says module not found when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.