473,385 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

thread stomp?

class1 (threading.Thread):
def __init__(self, dir):
self.dir = dir
threading.Thread.__init__(self)

def run(self):
do stuff in dir here...

class2 (threading.Thread):
def __init__(self, dir, dir2):
self.file = g
self.dir2 = dir2
threading.Thread.__init__(self)

def run(self):
do stuff in dir here...
output to dir2

class main
for i in dircache.listdir(dir):
//run over files
class1(dir).start()

for j in dircache.listdir(dir2):
//run over files, dependent on stuff in dir
class2(dir2).start()

think just using the loops above enough to prevent class2 threads from
starting before class1 threads done

not true

class2 threads seems to start prior to class1 threads done; class2
results depend on class1 finish first

any help?
Jun 27 '08 #1
2 1134
On Mon, 12 May 2008 20:00:52 GMT
pyn3wb <py****@pyn3wb.comwrote:
class1 (threading.Thread):
^
SyntaxError: invalid syntax

Give us a script that works. Ideally it should output something that
indicates what the error is.
//run over files
This is not a comment in Python.
class2 threads seems to start prior to class1 threads done; class2
results depend on class1 finish first
What are you trying to do? If all you care about is making one thread
depend on another finishing, why make two threads? Just have one
thread do one thing and then do the other.

Not every problem is a threading problem.

--
D'Arcy J.M. Cain <da***@druid.net | Democracy is three wolves
http://www.druid.net/darcy/ | and a sheep voting on
+1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.
Jun 27 '08 #2
On Mon, May 12, 2008 at 4:00 PM, pyn3wb <py****@pyn3wb.comwrote:
class main
Why are you making main a class? It should almost certainly be a
function (defined with "def", not "class").
for i in dircache.listdir(dir):
//run over files
class1(dir).start()
You've started a bunch of threads. If you want to wait for them to
all finish, you need to call .join() on them all. You can't do that
unless you save references to your threads, like this:

threads = []
for i in dircache.listdir(dir):
new_thread = class1(dir)
new_thread.start()
threads.append(new_thread)

for thread in threads:
thread.join()

Beyond that, the code you've posted is not correct. You've left off a
required ":" in your definition of class main, and your comments are
not valid python comments. Your for loops don't make a whole lot of
sense to me either. Are they supposed to be iterating across files in
a directory? If so, why do you start up all of your threads with
"dir" instead of "i" or "j" as the parameter to your new thread?

--
Jerry
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: adeger | last post by:
Having trouble with my first forays into threads. Basically, the threads don't seem to be working in parallel (or you might say are blocking). I've boiled my problems to the following short code...
4
by: Gilles Leblanc | last post by:
Hi I have started a small project with PyOpenGL. I am wondering what are the options for a GUI. So far I checked PyUI but it has some problems with 3d rendering outside the Windows platform. I...
7
by: Ivan | last post by:
Hi I have following problem: I'm creating two threads who are performing some tasks. When one thread finished I would like to restart her again (e.g. new job). Following example demonstrates...
4
by: Matthew Groch | last post by:
Hi all, I've got a server that handles a relatively high number of concurrent transactions (on the magnitude of 1000's per second). Client applications establish socket connections with the...
5
by: Razzie | last post by:
Hi all, A question from someone on a website got me thinking about this, and I wondered if anyone could explain this. A System.Threading.Timer object is garbage collected if it has no...
16
by: droopytoon | last post by:
Hi, I start a new thread (previous one was "thread timing") because I have isolated my problem. It has nothing to do with calling unmanaged C++ code (I removed it in a test application). I...
9
by: mareal | last post by:
I have noticed how the thread I created just stops running. I have added several exceptions to the thread System.Threading.SynchronizationLockException System.Threading.ThreadAbortException...
13
by: Bob Day | last post by:
Using vs2003, vb.net I start a thread, giving it a name before start. Code snippet: 'give each thread a unique name (for later identification) Trunk_Thread.Name = "Trunk_0_Thread" ' allow...
15
by: Laser Lu | last post by:
I was often noted by Thread Safety declarations when I was reading .NET Framework Class Library documents in MSDN. The declaration is usually described as 'Any public static (Shared in Visual...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.