Tagged Questions
174
votes
11answers
100k views
Is there any way to kill a Thread in Python?
Is it possible to terminate a running thread without setting/checking any flags/semaphores/etc.?
122
votes
3answers
11k views
Why is there no GIL in the Java Virtual Machine? Why does Python need one so bad?
I'm hoping someone can provide some insight as to what's fundamentally different about the Java Virtual Machine that allows it to implement threads nicely without the need for a Global Interpreter ...
107
votes
4answers
38k views
time.sleep — sleeps thread or process?
In Python for the *nix, does time.sleep() block the thread or the process?
81
votes
4answers
45k views
python multithreading for dummies
trying to find a simple example that clearly shows a single task being divided for multi-threading.
Quite frankly...
many of the examples are overly sophisticated thus.... making the flow tougher ...
78
votes
15answers
42k views
subprocess with timeout
Here's the Python code to run an arbitrary command returning its stdout data, or raise an exception on non-zero exit codes:
proc = subprocess.Popen(
cmd,
stderr=subprocess.STDOUT, # merge ...
62
votes
7answers
23k views
Python thread pool similar to the multiprocessing Pool?
Is there a Pool class for worker threads, similar to the multiprocessing module's Pool class?
I like for example the easy way to parallelize a map function
def long_running_func(p):
...
51
votes
5answers
18k views
How do threads work in Python, and what are common Python-threading specific pitfalls?
I've been trying to wrap my head around how threads work in Python, and it's hard to find good information on how they operate. I may just be missing a link or something, but it seems like the ...
50
votes
5answers
15k views
Multiprocessing vs Threading Python
I am trying to understand the advantages of the module Multiprocessing over Threading. I know that Multiprocessing get's around the Global Interpreter Lock, but what other advantages are there, and ...
41
votes
4answers
17k views
Can't pickle <type 'instancemethod'> when using python's multiprocessing Pool.map()
I'm trying to use multiprocessing's Pool.map() function to divide out work simultaneously. When I use the following code, it works fine:
import multiprocessing
def f(x):
return x*x
def go():
...
40
votes
6answers
15k views
Catch a thread's exception in the caller thread in Python
I'm very new to Python and multithreaded programming in general. Basically, I have a script that will copy files to another location. I would like this to be placed in another thread so I can output ...
40
votes
7answers
7k views
Why the Global Interpreter Lock?
What is exactly the function of Python's Global Interpreter Lock?
Do other languages that are compiled to bytecode employ a similar mechanism?
39
votes
8answers
4k views
Are locks unnecessary in multi-threaded Python code because of the GIL?
If you are relying on an implementation of Python that has a Global Interpreter Lock (i.e. CPython) and writing multithreaded code, do you really need locks at all?
If the GIL doesn't allow multiple ...
38
votes
7answers
21k views
Threading in Python
What's the best approach to writing multi-threaded applications in Python, I'm aware of the basic concurrency mechanisms provided by the language and also of Stackless Python. What would you ...
38
votes
5answers
16k views
Daemon Threads Explanation
In the Python documentation:
http://www.python.org/doc/2.5.2/lib/thread-objects.html
it says:
"A thread can be flagged as a ``daemon thread''. The significance of this flag is that the entire Python ...
34
votes
7answers
16k views
Threading in a PyQt application: Use Qt threads or Python threads?
I'm writing a GUI application that regularly retrieves data through a web connection. Since this retrieval takes a while, this causes the UI to be unresponsive during the retrieval process (it cannot ...