473,765 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

thread.error: release unlocked lock

So you have this problem, and you decide to use threads to solve it...

System is Python 2.3.3 on Solaris 9.

I'm using the classic Python thread model. Main thread puts stuff into
a Queue.Queue() and worker threads get stuff out of it and do their thing.

On occaision, I get an exception in the main thread when it tries to
put something into the Queue.

File "/usr/local/bin/poller.py", line 47, in fragnap_it
work_queue.put( (foo, bar, baz))
File "/usr/local/lib/python2.3/Queue.py", line 106, in put
self.fsema.rele ase()
thread.error: release unlocked lock

Seems like a bad thing, and I'm not sure what can be done. Should I catch
the thread.error and retry the put()? Or just give up and shutdown nicely?
(Or quickly finish the twisted version of this code?)

Any idea on the underlying cause of this exception?

....and now you have (at least) two problems.

Thanks.
Jul 18 '05 #1
4 7770
[John P.Speno]
So you have this problem, and you decide to use threads to solve it...

System is Python 2.3.3 on Solaris 9.

I'm using the classic Python thread model. Main thread puts stuff into
a Queue.Queue() and worker threads get stuff out of it and do their
thing.
A bounded queue or an unbounded queue? Blocking get/put or
non-blocking get/put? About how many items are in the queue? Since
nobody has reported your symptom before, some detail or other is going
to be important. How do the standard test_thread, test_threading, and
test_queue tests fare on this box? Was this Python configured to use
pthreads or native Solaris threads?
On occaision, I get an exception in the main thread when it tries to
put something into the Queue.

File "/usr/local/bin/poller.py", line 47, in fragnap_it
work_queue.put( (foo, bar, baz))
File "/usr/local/lib/python2.3/Queue.py", line 106, in put
self.fsema.rele ase()
thread.error: release unlocked lock

Seems like a bad thing, and I'm not sure what can be done. Should I
catch the thread.error and retry the put()? Or just give up and
shutdown nicely? (Or quickly finish the twisted version of this code?)

Any idea on the underlying cause of this exception?


Something has gone insane -- this should be impossible. fsema is a
mutex. put() always acquires fsema. Before it exits, put() releases
fsema again (unless the queue is bounded and put() has just filled
it). The error you're seeing is the mutex complaining about an
attempt to release it when it's not in the acquired state (which
should be impossible because put() acquires fsema before this point).
Jul 18 '05 #2
In <ma************ *************** ***********@pyt hon.org> Tim Peters <ti********@gma il.com> writes:
[John P.Speno]
I'm using the classic Python thread model. Main thread puts stuff into
a Queue.Queue() and worker threads get stuff out of it and do their
thing.
A bounded queue or an unbounded queue? Blocking get/put or
non-blocking get/put? About how many items are in the queue? Since
Thanks for asking. Here's what I can tell you.

Unbounded queues with non-blocking get/put. At most there are 1500 items
in the queue. There are 20 threads getting from the queue, and one
putting.

I did have bounded queues (max 40 items) and blocking puts but got the same
insane error then too.
nobody has reported your symptom before, some detail or other is going
to be important. How do the standard test_thread, test_threading, and
test_queue tests fare on this box? Was this Python configured to use
pthreads or native Solaris threads?


% grep -i thread pyconfig.h | grep -v ^/
#define HAVE_PTHREAD_H 1
#define HAVE_PTHREAD_SI GMASK 1
#define HAVE_THREAD_H 1
#define PTHREAD_SYSTEM_ SCHED_SUPPORTED 1
#define SIZEOF_PTHREAD_ T 4
#define WITH_THREAD 1

I think that means it is using native Solaris threads, assuming my reading
of thread.c is good.

All of test_thread, test_threading, and test_queue all passed.
Jul 18 '05 #3
[John P.Speno]
I'm using the classic Python thread model. Main thread puts stuff
into a Queue.Queue() and worker threads get stuff out of it and do
their thing.

[Tim Peters] A bounded queue or an unbounded queue? Blocking get/put or
non-blocking get/put? About how many items are in the queue?
Since nobody has reported your symptom before, some detail or
other is going to be important.
[John]
Thanks for asking. Here's what I can tell you.

Unbounded queues with non-blocking get/put.
That's odd -- non-blocking put doesn't really make sense with an
unbounded queue, esp. when only one thread does put(). It will work
anyway, it's just peculiar.

So if the queue is unbounded, the put() method is the only code
anywhere that acquires or releases fsema. That simplifies analysis,
but only in that it leads most directly to the conclusion that it's
impossible to get the error you're seeing. The candidates remaining
are things like compiler optimization bugs, buggy platform threads,
buggy C extension modules.

You should really file a bug report, on Python's SourceForge tracker
-- there's already too much detail to keep straight in
email/newsgroup.
At most there are 1500 items in the queue. There are 20 threads
getting from the queue, and one putting.

I did have bounded queues (max 40 items) and blocking puts but got
the same insane error then too.
Since nobody else has reported this problem, a successful conclusion
is going to require analyzing a small-as-possible failing test case.
I'm afraid that falls on you, unless someone else can reproduce your
symptom. Here's a start, modeling one plausible set of guesses for
exactly what all the above means:

"""
import threading
import time
from Queue import Queue, Empty
from random import random

class Worker(threadin g.Thread):
def run(self):
while True:
try:
k = q.get_nowait()
assert k == 1
except Empty:
pass
time.sleep(rand om()/10.0)

q = Queue()
ts = [Worker() for dummy in range(20)]
for t in ts:
t.start()

while True:
if q.qsize() > 1500:
print q.qsize()
time.sleep(3)
q.put_nowait(1)
time.sleep(0.00 1)
"""

I can apparently run that all day under 2.3.4 (or 2.4c1, which has an
entirely different Queue implementation) and not see anything odd.
Does it fail for you? If not, how does it differ from what your app
does? IOW, can you fiddle it so that it does fail?
How do the standard test_thread, test_threading, and
test_queue tests fare on this box? Was this Python configured to
use pthreads or native Solaris threads?

% grep -i thread pyconfig.h | grep -v ^/
#define HAVE_PTHREAD_H 1
#define HAVE_PTHREAD_SI GMASK 1
#define HAVE_THREAD_H 1
#define PTHREAD_SYSTEM_ SCHED_SUPPORTED 1
#define SIZEOF_PTHREAD_ T 4
#define WITH_THREAD 1

I think that means it is using native Solaris threads, assuming my
reading of thread.c is good.
I don't really know about Solaris config (another reason this would be
better in a bug report, where more people who care about bugs <wink>
would pay attention), but I'd *guess* it means you're using pthreads.
All of test_thread, test_threading, and test_queue all passed.


That figures. They check for sanity, but don't really count as stress tests.
Jul 18 '05 #4
In <ma************ *************** ***********@pyt hon.org> Tim Peters <ti********@gma il.com> writes:
[John]
Unbounded queues with non-blocking get/put.
[Tim]
That's odd -- non-blocking put doesn't really make sense with an
unbounded queue, esp. when only one thread does put(). It will work
anyway, it's just peculiar.


I'll bring this issue into a bug report but I wanted to clarify on
this one issue.

My worker threads used a bare queue.get() with no arguments which does
block. I mistakenly thought the default for the block argument was False
when, in fact, it defaults to True. Sorry about that. I'll modify your
example code accordingly and start testing this asap.

Take care.
Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2498
by: Bruce Bon | last post by:
The class below is intended to play a Sun audio file (.au) in the background while the main thread, which is servicing a GUI, continues without impact. It doesn't work. For a sound file that takes 3-5 seconds to play, the main thread hangs for that long. I have run this many times, with changes in printouts and insertion of strategic sleeps to try to make sure that the player thread gives up control, but apparently the call to...
31
2508
by: AlexeiOst | last post by:
Everywhere in documentation there are recommendations to use threads from thread pooling for relatively short tasks. As I understand, fetching a page or multiple pages (sometimes up to 50 but not tipical) from the Internet and doing some processing on those would be considered to be a big/long task for a thread from a pool. In our app it is possible to break the task into some small ones (thread per fetch and processing thereafter or event...
27
1739
by: Ritesh Raj Sarraf | last post by:
Hi, I have some basic doubts about thread. I have a list which has items in it which need to be downloaded from the internet. Let's say list is: list_items which has 100 items in it.
3
2175
by: Salvatore Di Fazio | last post by:
Hi guys, when I close the application I get the following error: ----------------------------- Traceback (most recent call last): File "main.py", line 88, in <module> while exit : pass KeyboardInterrupt Unhandled exception in thread started by Error in sys.excepthook:
23
5713
by: Boltar | last post by:
Hi I'm writing a threading class using posix threads on unix with each thread being run by an object instance. One thing I'm not sure about is , if I do the following: myclass::~myclass() { : : do stuff
3
5589
by: NaeiKinDus | last post by:
Hello, i'm trying to program a thread that would be locked (by a mutex) and that would only be unlocked once that a function (generating data) is done. The purpose is to generate data, and unlock the mutex in order to activate the thread once the data is generated. I have to do it this way, i can only call the thread if the data are generated. ******************************************************** step 1: initialize the mutex
3
2377
by: Lars Uffmann | last post by:
I have this wxWidgets OnButtonClick event handler, that apparently holds a lock on all widgets in my form, but this event handler is supposed to end a thread in the background - while that thread is supposed to update widget content. So if I want to wait for the thread to end in the event handler, I have 2 threads waiting on each other - with the one in the background waiting to access the widget content. My current workaround is to...
3
3078
by: andreas.zetterstrom | last post by:
I'm implementing some different c++ classes which I want to be thread safe. All these classes contain lists or arrays of some kind. I'm using protected sections to make them thread safe. The question then is: how do you in a nice safe way pick values out of the list? The easiest way is to have a pair of Lock, Unlock functions, but this also presents a lot of ways of doing a misstake. Say the list class has 5 functions, one to get the...
12
2082
by: Ronny | last post by:
Thanks Chris, Looks nice but I miss the dual way communication. In the main thread to deliver paramters and data to the worker thread- how can I do that? Regards Ronny Take a look at the background worker thread component. It has what you want built into it. http://msdn.microsoft.com/en-us/library/8xs8549b.aspx
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9399
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10163
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9957
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9835
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7379
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.