3 Replies - 569 Views - Last Post: 22 April 2015 - 03:40 PM Rate Topic: -----

#1 [email protected]   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 8
  • Joined: 22-April 15

Problem with threading + queue

Posted 22 April 2015 - 09:16 AM

Hi every one im learning python 3, today i was playing with trheading module and im habing problems with this code:

import threading
import queue


dictionary = 'pass.txt'
password = 'chicken'

def checkPass(anyPass):

   global password

   if anyPass == password:
      print('The password is :'+ str(anyPass))

   else:
      print('Its not: ', anyPass )
def worker():
   while True:
      work = q.get()
      checkPass(work)
      q.task_done()

q = queue.Queue()

for i in range(2):
   t = threading.Thread(target = worker)
   t.daemon = True
   t.start()

with open('pass.txt','r') as file:
   for line in file:
      q.put(line)

print('Waiting for a coincidece')
q.join()
print('Finish')



It dont throw error but its not doing what it should..telling me when a word in the queue is equal to my variable password. Anyone have an idea of whats going on there, or what im doing wrong?

Is This A Good Question/Topic? 0
  • +

Replies To: Problem with threading + queue

#2 atraub   User is offline

  • Pythoneer
  • member icon

Reputation: 837
  • View blog
  • Posts: 2,271
  • Joined: 23-December 08

Re: Problem with threading + queue

Posted 22 April 2015 - 09:55 AM

I'll take a look at your code when I have time. In the meantime, one thing you should know is that Python's threads aren't "real" threads. They all execute on the same process so nothing is truly happening in parallel.
Was This Post Helpful? 0
  • +
  • -

#3 [email protected]   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 8
  • Joined: 22-April 15

Re: Problem with threading + queue

Posted 22 April 2015 - 10:30 AM

View Postatraub, on 22 April 2015 - 09:55 AM, said:

I'll take a look at your code when I have time. In the meantime, one thing you should know is that Python's threads aren't "real" threads. They all execute on the same process so nothing is truly happening in parallel.


Thanks you very much for your time!:)
Was This Post Helpful? 0
  • +
  • -

#4 [email protected]   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 8
  • Joined: 22-April 15

Re: Problem with threading + queue

Posted 22 April 2015 - 03:40 PM

I find what was the problem. In the txt file the list with possible passwords have an space at the end of each word. So adding a strip() function at the line:
q.put(line.strip())

Solve the problem.

Thanks you anyway for you time.:)
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1