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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:50:00+00:00 2026-05-16T15:50:00+00:00

>>> l = Lock() >>> l.acquire() True >>> l.release() >>> l.release() Traceback (most recent

  • 0
>>> l = Lock()
>>> l.acquire()
True
>>> l.release()
>>> l.release()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: semaphore or lock released too many times

throws a ValueError exception. How can I prevent to release a lock more than once? Something like l.is_released() ?

  • 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-16T15:50:01+00:00Added an answer on May 16, 2026 at 3:50 pm

    The question is a bit unclear. You either need to use semaphores instead of locks or check if lock is locked.

    Python’s locks are not the same as locks on .Net, for example. Python’s Lock once unlocks releases ALL other threads that acquired() on the same lock and blocked for the time being. Any thread can release and all go at the same time. So, instead of doing second relase, do

    if l.locked():
        l.release()
    

    If you want “queue” behavior, where only one tread will get ownership of a lock once some other releases, use Semaphore, Event or some other similar class that allows nested locking and queuing behavior.

    It’s interesting to note that other languages/loolkits, like .Net, do lock queuing natively, where threads can pile up lock.acquire in order, block and take ownership of the lock object in the order of acquire queue, not release all at once.

    (Edit: forgot to put parents as in “if l.locked: l.realse()”. Corrected the code. Lock.locked is confirmed to be a present method in cPython 2.6.x, 3.x, IronPython 2.6.1)

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

Sidebar

Ask A Question

Stats

  • Questions 535k
  • Answers 535k
  • 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 You might try something like this: function initPlayer(playerQueue){ if(playerQueue.length >… May 17, 2026 at 1:04 am
  • Editorial Team
    Editorial Team added an answer INSERT INTO table SELECT 'jonny', NULL FROM dual -- Not… May 17, 2026 at 1:04 am
  • Editorial Team
    Editorial Team added an answer PHP doesn't have any equivalent to Application State. Your best… May 17, 2026 at 1:04 am

Trending Tags

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

Top Members

Related Questions

I have the following consumer code: .... while 1: time.sleep(self.sleeptime) cond.acquire() #acquire the lock
I have threaded code where each thread needs to write to the same file.
Background I'm trying to implement block file locking in my C# application. The built-in
Is it possible to write a class such that other programmers cannot acquire a
How to make a multi-thread python program response to Ctrl+C key event? Edit: The
This is probably a rudimentary question, but I'm new to threaded programming in Python
I have an app where I need to prevent users from editing data while
I have some questions about the following code: using System; namespace ConsoleApplication2 { public
To solve a problem (and better my understanding of multitasking) I have written a
We are seeing an intermittent issue on development and production machines whereby our log

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.