Thread View: pl.comp.lang.python
2 messages
2 total messages
Started by Marcin Łabuz
Sat, 19 Sep 2009 12:55
Thread
Author: Marcin Łabuz
Date: Sat, 19 Sep 2009 12:55
Date: Sat, 19 Sep 2009 12:55
36 lines
2037 bytes
2037 bytes
Witam,
Od niedawna staram się poznać Pythona i napotkałem mały problem.
Dotyczy on wątków. Mimo użycia setDaemon(True), wątki zdają sie czekać
na siebie, tzn watek nr 1 czeka aż skończy pracować watek 2 i dopiero
wtedy zabiera sie do dzieła. Chce żeby oba wątki pracowały
jednosczesnie, co robię źle? Bardzo proszę o pomoc.
import time
from threading import Thread
class Printer:
def __init__(self):
self.Watek().run()
for x in range(1,11):
print "%s. Watek 1" % x
time.sleep(1)
class Watek(Thread):
def __init__(self):
Thread.__init__(self)
self.setDaemon(True)
def run(self):
for x in range (1,11):
print "%s. Watak 2" % x
time.sleep(1)
if __name__ == "__main__":
Printer()
Pozdrawiam
Re: Thread
Author: ryniek90
Date: Sat, 19 Sep 2009 13:27
Date: Sat, 19 Sep 2009 13:27
40 lines
2391 bytes
2391 bytes
On 19 Wrz, 14:55, Marcin Łabuz <lab...@gmail.com> wrote: > Witam, > > Od niedawna staram się poznać Pythona i napotkałem mały problem. > Dotyczy on wątków. Mimo użycia setDaemon(True), wątki zdają sie czekać > na siebie, tzn watek nr 1 czeka aż skończy pracować watek 2 i dopiero > wtedy zabiera sie do dzieła. Chce żeby oba wątki pracowały > jednosczesnie, co robię źle? Bardzo proszę o pomoc. > > import time > from threading import Thread > > class Printer: > > def __init__(self): > > self.Watek().run() > > for x in range(1,11): > print "%s. Watek 1" % x > time.sleep(1) > > class Watek(Thread): > > def __init__(self): > Thread.__init__(self) > self.setDaemon(True) > > def run(self): > for x in range (1,11): > print "%s. Watak 2" % x > time.sleep(1) > > if __name__ == "__main__": > Printer() > > Pozdrawiam Zajrzyj tutaj ( http://www.devshed.com/c/a/Python/Basic-Threading-in-Python/ ).
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads