Threads with python

0

I am trying to make updates to a database that is located in MongoDB. For the number of records I need to do it by threads so that this is much faster.

In the code that I put down it does but I see that it repeats the values so it does not work for me.

from pymongo import MongoClient
from time import time
import _thread



clienteRest = MongoClient("mongodb://localhost")
db = clienteRest.XXX
col = db.xxx

cursor = col.find({})
c = 0

def busqueda(threadName,delay):
    print(threadName)
    print(a['_id'])
    tam = len(a['Clave'])
    print(tam)
    col.update({"_id": a['_id']}, {"$set": {"Clave": "000001"}})



for a in cursor:
    start_time = time()
    try:
        _thread.start_new_thread(busqueda, ("Thread-1", 1,))
        _thread.start_new_thread(busqueda, ("Thread-2", 2,))
    except:
        print("Error: unable to start thread")
    elapsed_time = time() - start_time
    print("Elapsed time: %0.10f seconds." % elapsed_time)

I hope you can help me.

Greetings!

    
asked by Memo 23.05.2018 в 17:48
source

0 answers