The new forums will be named Coin Return (based on the most recent vote)! You can check on the status and timeline of the transition to the new forums here.
The Guiding Principles and New Rules document is now in effect.
The Parent spawns an instance of Child, and needs to know when Child has finished running. Right now, Parent contains a condition variable, is there a way to pass that condition variable to Child?
What I've been trying is
class Child(Thread):
def __init__(self, Condition c):
Thread.__init__(self)
self.monitor=c
def run(self):
for i in range(0, 5):
print "hello from child", i
This is the best resource on Python threading I've found. Communication between threads is hard. Do it exactly like he says, and it will work (I've done it).
I'm far from a Python expert, but I've done something similar in other languages by forking the parent, and you can do that in Python.
It depends on what you're trying to do. One of the performance-related problems in Python when you use threads is because of the GIL (global interpreter lock). Only one thread may use the interpreter at a time, and the main practical implication of this is that you can't take advantage of multiple cores. While that link mentions thread pools and queues that isn't a solution for that, and manually managing child processes is cumbersome.
In Python 2.6+ and 3.0+ the multiprocessing module was added which makes dealing with child processes more convenient and lets you do things like create process pools. If you're using the *_async methods of the pool you can specify a callback when the function returns.
OP: I highly recommend reading this for information on using threads in Python.
Barrakketh on
Rollers are red, chargers are blue....omae wa mou shindeiru
Yea, this doesn't seem to be working. I think I might just create a global Condition() variable instead.
How do you create static global variables in Python?
#same file:
global variable1
def function():
global variable1 #Yes, you define it twice. Skip this, and you can still read the variable, but you can't write.
variable1=3
#different file
import file1
def function2():
file1.variable1 = 2
Posts
Hm... that would work, but I don't think I'll be able to do that, because the assignment specifies separate Parent and Child classes.
GT: Tanky the Tank
Black: 1377 6749 7425
pretty sure that's not legal python.
Doc: I tried this, and it doesn't seem to work. Passing the condition from parent to child seems to create a new instance of the condition.
GT: Tanky the Tank
Black: 1377 6749 7425
This is the best resource on Python threading I've found. Communication between threads is hard. Do it exactly like he says, and it will work (I've done it).
It depends on what you're trying to do. One of the performance-related problems in Python when you use threads is because of the GIL (global interpreter lock). Only one thread may use the interpreter at a time, and the main practical implication of this is that you can't take advantage of multiple cores. While that link mentions thread pools and queues that isn't a solution for that, and manually managing child processes is cumbersome.
In Python 2.6+ and 3.0+ the multiprocessing module was added which makes dealing with child processes more convenient and lets you do things like create process pools. If you're using the *_async methods of the pool you can specify a callback when the function returns.
OP: I highly recommend reading this for information on using threads in Python.
How do you create static global variables in Python?
GT: Tanky the Tank
Black: 1377 6749 7425