niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Programming » python
Can thread start other threads?
Post new topic   Reply to topic Page 1 of 1 [3 Posts] View previous topic :: View next topic
Author Message
John Henry
*nix forums beginner


Joined: 14 Jun 2005
Posts: 18

PostPosted: Tue Jul 18, 2006 9:58 pm    Post subject: Can thread start other threads? Reply with quote

Can Python thread start threads? It appears not. When I do that, the
sub-threads gets to certain point and just sit there. If I run the
code serially and not run the sub-thread code as threads, everything is
fine.

I throught the problem is when you run multiple processes of Pythons...
Back to top
Diez B. Roggisch
*nix forums Guru


Joined: 20 Feb 2005
Posts: 882

PostPosted: Tue Jul 18, 2006 10:33 pm    Post subject: Re: Can thread start other threads? Reply with quote

John Henry schrieb:
Quote:
Can Python thread start threads? It appears not. When I do that, the
sub-threads gets to certain point and just sit there. If I run the
code serially and not run the sub-thread code as threads, everything is
fine.

It can.

import threading, time


class Test(threading.Thread):
def __init__(self, num):
threading.Thread.__init__(self)
self._num = num
self.setDaemon(True)
self.start()

def run(self):
if self._num > 0:
t = Test(self._num - 1)
while True:
time.sleep(.2)
print "T_%i" % self._num


t = Test(4)

while True:
time.sleep(2.0)


Quote:
I throught the problem is when you run multiple processes of Pythons...


No.

Whatever you do, it must be the cause. Without code - nobody can tell
you why.

Diez
Back to top
John Henry
*nix forums beginner


Joined: 14 Jun 2005
Posts: 18

PostPosted: Tue Jul 18, 2006 11:00 pm    Post subject: Re: Can thread start other threads? Reply with quote

Thanks for the confirmation.

I will see if I can reduce the code down to something managable and
post the failing code.



Diez B. Roggisch wrote:
Quote:
John Henry schrieb:
Can Python thread start threads? It appears not. When I do that, the
sub-threads gets to certain point and just sit there. If I run the
code serially and not run the sub-thread code as threads, everything is
fine.

It can.

import threading, time


class Test(threading.Thread):
def __init__(self, num):
threading.Thread.__init__(self)
self._num = num
self.setDaemon(True)
self.start()

def run(self):
if self._num > 0:
t = Test(self._num - 1)
while True:
time.sleep(.2)
print "T_%i" % self._num


t = Test(4)

while True:
time.sleep(2.0)


I throught the problem is when you run multiple processes of Pythons...


No.

Whatever you do, it must be the cause. Without code - nobody can tell
you why.

Diez
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [3 Posts] View previous topic :: View next topic
The time now is Thu Jan 08, 2009 6:40 am | All times are GMT
navigation Forum index » Programming » python
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts bind keyboard POWER button to start some program Vladi Lemurov Debian 1 Fri Jul 21, 2006 6:00 am
No new posts setting serial start value Greg Philpott PostgreSQL 4 Fri Jul 21, 2006 1:32 am
No new posts Is there a boot loader that can load a file a start up an... christopher.mcrorie@gmail Setup 1 Thu Jul 20, 2006 2:57 am
No new posts New to threads. How do they work? gel python 4 Thu Jul 20, 2006 2:08 am
No new posts unable to start db2 admin server qin_23 IBM DB2 5 Wed Jul 19, 2006 3:31 pm

Web Advertising | Yugioh | Debt Consolidation | Loans | Mortgage
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1650s ][ Queries: 16 (0.0890s) ][ GZIP on - Debug on ]