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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T12:09:30+00:00 2026-06-03T12:09:30+00:00

I have a feeling I’m being stupid. Given this ini file: [main] source1 =

  • 0

I have a feeling I’m being stupid. Given this ini file:

[main]
source1 = ./testing/sdir1
sync1 = ./testing/sydir1
archive1 = ./testing/adir1
source2 = ./testing/sdir2
sync2 = ./testing/sydir2
archive2 = ./testing/adir2
[logging]
log_dir = .
log_file = pixelsync.log
log_level = DEBUG

The following code hangs:

import ConfigParser

CONFIG_FILE = 'pixelsync.ini'

def parse_config() :
    """read details from the config file"""
    global CONFIG_FILE
    config = ConfigParser.SafeConfigParser()
    config.read(CONFIG_FILE)
    index = 1
    while True :
        if config.has_option('main', 'source' + str(index)) and \
                    config.has_option('main', 'sync' + str(index)) and \
                    config.has_option('main', 'archive' + str(index)) :

            result = ( config.get('main', 'source' + str(index)),
                       config.get('main', 'sync' + str(index)),
                       config.get('main', 'archive' + str(index)))
            index += 1
        else :
            if index == 1 :
                print "could not setup any trios from the config file. exiting."
                sys.exit(1)
    return result

if __name__ == '__main__' :
    options = parse_config()

It hangs on the ‘if’ clause.

If I replace the ‘if’ clause with :

if config.has_option('main', 'source1' ) and \
                    config.has_option('main', 'sync1' ) and \
                    config.has_option('main', 'archive1' ) :

it doesn’t hang. (doesn’t do what I want since I need to loop through an arbitrary number of sets of three, but it doesn’t silently hang.

Python v2.7.3 on ubuntu 12.04 (Precise), 32bit.

  • 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-03T12:09:31+00:00Added an answer on June 3, 2026 at 12:09 pm

    The reason your program hangs is it never breaks out of the loop – it goes on forever. Rather than simply setting result, you need to return it. (An alternative is to set it and then use break to break out of the loop and return, but that is somewhat roundabout. It’s better to simply return it straight away.

    Note that doing while True: and counting like that isn’t very Pythonic, the preferred approach is to instead use itertools.count().

    E.g:

    import itertools
    
    ...
    
    for index in itertools.count(1):
        ...
    

    Note that this shows a design flaw. You probably want to have a way of knowing if you are never going to get a suitable result. Infinite loops are generally bad.

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

Sidebar

Related Questions

I have a feeling this is a stupid question but I can't find the
I have a feeling that Apache is using a different php.ini file that the
I have a feeling that this is stupid question, but I'll ask anyway... I
I have a feeling this XML is not valid, can someone please explain why?
I have the feeling the answer to this question is no but I figured
I have a feeling that this query is pretty easy to construct, I just
I have a feeling I am completely borking this MySQL query but I'll ask
I have a feeling that I am going to ask a stupid question, yet
I somehow have the feeling that modern systems, including runtime libraries, this exception handler
I have a feeling I'm missing something pretty simple here but, in this one

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.