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 9277371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T17:05:30+00:00 2026-06-18T17:05:30+00:00

I need to open a port to the serial device but if it has

  • 0

I need to open a port to the serial device but if it has not been opened or there is an exception it must continuously try to open the door until it opens. Python 2.7.3 after a while I get this error:

“RuntimeError: maximum recursion depth exceeded while calling a Python
object”

Can you help me?

My code:

def opendisplay():
    try:
        lcd = serial.Serial(
        port='/dev/display', 
        baudrate=9600, 
        timeout=0,
        parity=serial.PARITY_NONE,
        stopbits=serial.STOPBITS_ONE,
        bytesize=serial.EIGHTBITS
        )
    except Exception, e:
        print "Error! can't connect to display Lcd check USB-Serial \n" + str(e)
        opendisplay()   
    return lcd

dsp=opendisplay()
  • 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-06-18T17:05:31+00:00Added an answer on June 18, 2026 at 5:05 pm

    As Martin/Shadow says, loop instead of recurse:

    def opendisplay():
        while True:
            try:
                # Try to connect
                lcd = serial.Serial(...)
                return lcd
            except Exception as e:
                # Connection failed
                print "Error! etc"
                time.sleep(1)
    

    If you want to only keep trying for a minute, you can use for _ in range(60) instead

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

Sidebar

Related Questions

Hey can any one tell me should i need open a port for outgoing
I'm creating Content management system in asp.net. But I need open source cascading stylesheet
I need to open a link from within jQuery but i need to avoid
I need to open port 8069 on external IP. from router point, internal-ip and
I'm doing a project for serial port.. I need to select the available com
i have a problem. i try to listen serial port(COM20), and then i receive
I need to open a firewall port so that I can connect from one
I'm writing a .Net app that will need to talk to a serial port
I need a quick way to find out if a given port is open
I need to find whether a port Ex. port 8080 is opened on a

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.