Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Python and threads

Reply
Thread Tools

Python and threads

 
 
vedrandekovic@yahoo.com
Guest
Posts: n/a
 
      01-18-2009
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
 
Reply With Quote
 
 
 
 
Stefan Behnel
Guest
Posts: n/a
 
      01-18-2009
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> 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
 
Reply With Quote
 
 
 
 
Diez B. Roggisch
Guest
Posts: n/a
 
      01-18-2009
(E-Mail Removed) schrieb:
> 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

 
Reply With Quote
 
vedrandekovic@yahoo.com
Guest
Posts: n/a
 
      01-18-2009
On 18 sij, 17:48, "Diez B. Roggisch" <(E-Mail Removed)> wrote:
> (E-Mail Removed) schrieb:
>
>
>
> > 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


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
 
Reply With Quote
 
Stefan Behnel
Guest
Posts: n/a
 
      01-18-2009
(E-Mail Removed) wrote:
> 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
 
Reply With Quote
 
vedrandekovic@gmail.com
Guest
Posts: n/a
 
      01-19-2009
On 18 sij, 21:27, Stefan Behnel <(E-Mail Removed)> wrote:
> (E-Mail Removed) wrote:
> > 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


Hello,

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


Regards,
John
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java Threads - Get running threads Pedro Pinto Java 2 04-08-2008 11:44 PM
[new to threads] threads with UI and loop Une bévue Ruby 0 06-14-2006 10:22 AM
TB View, Threads, Threads with unread The Invisible Man Firefox 1 03-20-2006 02:09 AM
Standard Threads vs Weightless Threads yoda Python 2 08-01-2005 09:12 PM
threads without threads sindica@gmail.com C Programming 4 08-27-2004 09:25 PM



Advertisments