Duplicate logs while spawning two threads

This is the place for queries that don't fit in any of the other categories.

Duplicate logs while spawning two threads

Postby jainshasha » Tue Feb 19, 2013 5:52 am

Hi,

While spawning two different threads using Thread from threading module i am getting duplicate logs in log file.

Creating two threads in this way :
Code: Select all
t = Thread(target = check_Input_Status_Action.thresholdCheck, args = (thresholdTime,))
t.start()

t1 = Thread(target = check_Input_Status_Action.main, args = (sys.argv,))
t1.start()


But if call the above two statements with small sleep in between them then the duplicate log problem doesn't coming.

Could you please help me in knowing that when we spawn two threads in the consecutive statements does this problem occur or do we need to give some time lag in while calling these two statements.


Thanks
jainshasha
 
Posts: 1
Joined: Tue Feb 19, 2013 5:51 am

Re: Duplicate logs while spawning two threads

Postby stranac » Tue Feb 19, 2013 10:44 am

I edited your post to include code tags.
Please read this before posting again.

As for your problem, I'm afraid I can' really help, since I never used threads much.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1097
Joined: Thu Feb 07, 2013 3:42 pm

Re: Duplicate logs while spawning two threads

Postby Yoriz » Tue Feb 19, 2013 1:07 pm

Your two threaded functions/methods are probably working on the same data at the same time, by putting a delay in place it allow's the first thread to change the data before the second one accesses it.
It depends on what your functions are actually doing but you may need a single thread that picks jobs from a queue so that each job is completed before the next starts or if the jobs works on seperate data you can have more then one thread pick jobs from a queue so they dont work on the same job.
New Users, Read This
Join the #python-forum IRC channel on irc.freenode.net!
Spam topic disapproval technician
Windows7, Python 2.7.4., WxPython 2.9.5.0., some Python 3.3
User avatar
Yoriz
 
Posts: 781
Joined: Fri Feb 08, 2013 1:35 am
Location: UK


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 3 guests

cron