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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:59:55+00:00 2026-05-31T17:59:55+00:00

I have a python program that I am currently working on which is working

  • 0

I have a python program that I am currently working on which is working pretty well except for the fact that I am running into “recursion depth” issues and I am not sure how to rework my program to avoid this.

my program is basically something like this in a nutshell:

def foo()
    x = 0 # 

    while x != 1:
        x = (mydll.InPortB(base+1)) & 1 # this is a hardware input like a push button(on or off)
        time.sleep(0.5)

     bar = ser.readline() # input from serial source
     if len(bar) != 10:
         foo()
     ''' it continues checking "bar" using some more if statement. Finally when the
         logic is satisfied the program outputs something but still restarts foo() as
         I need the program to run endlessly but I am not sure how to fix the recursive
         nature of the program'''
      if bar = 1234567890:
          print "yay you win"
          foo()
#start
foo()

Ultimately my program works as it is but eventually will crash out with the recursion limit error so not ideal as I need this program to run endlessly but being a total newb to programming I am unsure how to fix it. I did try to split my program into two or three separate function rather than just the one but it was still exhibiting the recursion issue.

Thanks for any input. If anyone needs more code I can post it but thought the small piece should be sufficient to see where I am going. Any help would be appreciated.

  • 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-31T17:59:57+00:00Added an answer on May 31, 2026 at 5:59 pm

    I would try this since it repeatedly calls the function at the same recursion level:

    def foo()
        x = 0 # 
        while arming != 1:
            x = (mydll.InPortB(base+1)) & 1 # this is a hardware input like a push button(on or off)
            time.sleep(0.5)
    
         bar = ser.readline() # input from serial source
         if len(bar) != 10:
    
         ''' it continues checking "bar" using some more if statement. Finally when the
             logic is satisfied the program outputs something but still restarts foo() as
             I need the program to run endlessly but I am not sure how to fix the recursive
             nature of the program'''
          if bar = 1234567890:
              print "yay you win"
    
    #start
    while 1:
        foo()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a working Python based program that I want to run as a
I have a possibly long running program that currently has 4 processes, but could
I have a Python program that uses the threading module. Once every second, my
I have a python program that reads floating point values using the following regular
I have a python program that opens several urls in seperate tabs in a
I have a python program that is going to eat a lot of memory,
I have a simple python program that I'd like to daemonize. Since the point
I have a python program/file that I want to run repeatedly and calculate the
I have a Python program (with Django - does this matter?) that I want
I have an old C# program that is being ported to Python 3 for

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.