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


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,))

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

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.

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
Posts: 1790
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.
Due to the reasons discussed here we will be moving to python-forum.io/ on October 1 2016
This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
User avatar
Posts: 1672
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

Return to General Coding Help

Who is online

Users browsing this forum: Google [Bot] and 9 guests