Hi,
I am quite new to Python but i found it really interesting and useful so I am trying to write even the smallest tools in this language. During this passion of creating everything in Python I get stuck on the following problem.
I want to create a simple class that will be used as an interface to some application. The class shall start the application as a separate thread and try to connect to it. So, it looks like this
When I try this approach I fail and I really don't know why. If i move the os.spawn ... statement outside the class it will work and os.waitpid will wait until the process is finished.
What am I doing wrong? Is it allowed to start separate thread from the constructor of a class?
Thanks in advance for any help and hints
Best regards,
I am quite new to Python but i found it really interesting and useful so I am trying to write even the smallest tools in this language. During this passion of creating everything in Python I get stuck on the following problem.
I want to create a simple class that will be used as an interface to some application. The class shall start the application as a separate thread and try to connect to it. So, it looks like this
Code:
class MyClass:
__init__(self):
self.pid = os.spawnl(os.P_NOWAIT,"some_app","some_app","param1","param2")
# the class ends here
myApp = MyClass
os.waitpid(myApp.pid,0)
print "bye"
What am I doing wrong? Is it allowed to start separate thread from the constructor of a class?
Thanks in advance for any help and hints
Best regards,
Comment