Python and threads

V

vedrandekovic

Hello again,

Thanks for previous help on "Start two threads in same time" it was
useful,but when I run this
two threads, I think they don't start at the same time, here is my
code snippet:


import threading

class ThreadedClass1(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)

def run(self):
a=True
while a==True:
bm=my_module.MyClass()
a=bm.get_Python_Process_Usage_Function() #Returns True
or False

class ThreadedClass2(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)

def run(self):
os.popen("my_python_script.py")



threaded_obj = ThreadedClass1()
threaded_obj.start()
threaded_obj2 = ThreadedClass2()
threaded_obj2.start()

Regards,
John
 
S

Stefan Behnel

Thanks for previous help on "Start two threads in same time" it was
useful,but when I run this
two threads, I think they don't start at the same time

That's normal. Threading is an unpredictable concurrency pattern. Things
often don't happen the way one would want them to.

Stefan
 
D

Diez B. Roggisch

Hello again,

Thanks for previous help on "Start two threads in same time" it was
useful,but when I run this
two threads, I think they don't start at the same time, here is my
code snippet:


import threading

class ThreadedClass1(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)

def run(self):
a=True
while a==True:
bm=my_module.MyClass()
a=bm.get_Python_Process_Usage_Function() #Returns True
or False

class ThreadedClass2(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)

def run(self):
os.popen("my_python_script.py")



threaded_obj = ThreadedClass1()
threaded_obj.start()
threaded_obj2 = ThreadedClass2()
threaded_obj2.start()

If you want to synchronize two or more threads, you need to do so
manually using objects like Locks, Events, Conditions and Semaphores.
See the threading module.

Even if you managed to get two threads started simultaneously (which the
OS doesn't even offer IINM), the would soon run out of sync.

How about you tell us what you *want*, and we tell you if and how it's
possible to do that.

Diez
 
V

vedrandekovic

(e-mail address removed) schrieb:











If you want to synchronize two or more threads, you need to do so
manually using objects like Locks, Events, Conditions and Semaphores.
See the threading module.

Even if you managed to get two threads started simultaneously (which the
  OS doesn't even offer IINM), the would soon run out of sync.

How about you tell us what you *want*, and we tell you if and how it's
possible to do that.

Diez

Hello,

and thanks for all previous help.I want to measure memory usage of
executed python script.I'am working on windows XP.

Regards,
John
 
S

Stefan Behnel

and thanks for all previous help.I want to measure memory usage of
executed python script.I'am working on windows XP.

Could you qualify "measure"? Do you mean:

a) "debug" (permanently high accuracy, potentially high runtime overhead)
b) "monitor" (high accuracy, low/medium-resolution surveillance, no runtime
overhead)
c) "find out" (low accuracy or just max usage, no permanent observation)

?

Stefan
 
V

vedrandekovic

Could you qualify "measure"? Do you mean:

a) "debug" (permanently high accuracy, potentially high runtime overhead)
b) "monitor" (high accuracy, low/medium-resolution surveillance, no runtime
              overhead)
c) "find out" (low accuracy or just max usage, no permanent observation)

?

Stefan

Hello,

I want to "find out" , sorry for this "measure".


Regards,
John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,089
Latest member
Ketologenic

Latest Threads

Top