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

  • Home
  • SEARCH
  • 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 159219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:49:12+00:00 2026-05-11T10:49:12+00:00

When writing concurrent/multithreaded code in Python, is it especially important to follow the Easier

  • 0

When writing concurrent/multithreaded code in Python, is it especially important to follow the ‘Easier to Ask for Forgiveness than Permission’ (EAFP) idiom, rather than ‘Look Before You Leap’ (LBYL)? Python’s exceptionally dynamic nature means that almost anything (e.g., attribute removal) can happen between looking and leaping—if so, what’s the point? For example, consider

# LBYL if hasattr(foo, 'bar'):     baz = foo.bar 

versus

# EAFP try:     baz = foo.bar except AttributeError:     pass 

In the LBYL example, the bar attribute could disappear from foo before the actual call to foo.bar is made, so do you gain anything from the check? If there’s a risk the attribute might disappear, you need locks and/or try/except clauses anyway.

One possible argument here is that this example makes the extremely pessimistic assumption that ‘antagonistic code’ is running that could yank the rug from under you at any moment. In most use cases, this is highly unlikely.

  • 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. 2026-05-11T10:49:13+00:00Added an answer on May 11, 2026 at 10:49 am

    Your thoughts are correct. Some additional points:

    If the attribute exists most of the time, try:except: might be much faster than the LBYL idiom.

    If you don’t like the try: except: syntax, you can also write:

    item = getattr(foo, 'bar', None) if item is None:     .... else:     .... 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 91k
  • Answers 91k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I'm the PHP guy (that also does .NET) that is… May 11, 2026 at 6:19 pm
  • Editorial Team
    Editorial Team added an answer Concurrent Programming on Windows has some great content on this… May 11, 2026 at 6:19 pm
  • Editorial Team
    Editorial Team added an answer In your "for word in wordlist" loop, each word will… May 11, 2026 at 6:19 pm

Related Questions

I've read a lot recently about how writing multi-threaded apps is a huge pain
I'm currently trying to pass a mono threaded program to multithread. This software do
Today I had to fix some older VB.NET 1.0 code which is using threads.
First some background on the application. I have an application processing many independent tasks

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.