1

プロデューサーがデータベースを読み取り、結果を Web サイトに配置するプロデューサー、コンシューマー アプリケーションがあります。成功すると、消費者はトランザクションの ID を取得し、データベースを更新します。

プログラムは、更新の実行が試行されるまで、必要に応じて実行されます。このエラー 'HY000'、'The driver did not supply an error!' で失敗することがあります。

コードは問題なく快適にファイルに書き込むことができます。

これを修正するにはどうすればよいですか? データベースを更新する必要があります。

ありがとうございます... mssql 2008でpyodbcでpython 2.7を使用しています。

以下のコード

    #!/usr/bin/env python

    from urlparse import urlparse
    from threading import Thread
    import httplib, sys
    import Queue
    import urllib2
    import urllib
    from time import localtime, strftime
    from ConfigParser import SafeConfigParser
    from functions import Functions
    from pyodbcclass import db_mssql

    now = strftime("%y-%m-%d-%H%M%S", localtime())
    k = db_mssql()


    thread_list = []
    thread_list2 = []
    getFromDBQueue = Queue.Queue()
    updateDBQueue = Queue.Queue()
    number_of_consumer_threads = 3

    def putURL():
        querySql = "select distinct top 3 id,url from tblURL where processed=0  order by id asc"

        re = k.query2(querySql)
        if re:

            for r in re:
                id = r.id
                params = urllib.urlencode({'user': user, 'password': password})
                ourl = urlini + "?%s" % params
                urlplusid = {'url':ourl.strip(),'id':id}
                getFromDBQueue.put(urlplusid)

    def getURL(thread_id):
        while 1:
            try:
                URL_toget = getFromDBQueue.get(block=False)
                url2 = URL_toget['url']
                msgid2 = URL_toget['id']
            except Queue.Empty:
                print "thread exiting, id: " + str(thread_id) + "++getFromDB++"
                sys.exit()
            status,url = getStatus(url2)
            if status == 200:
                updateDBQueue.put(msgid2)

            print(status)

    def updateDB(thread_id):
        while 1:
            try:

                id2 = updateDBQueue.get(block=False)
                if id2:
                    params = ['true',id2]
                    sqlupdate = "UPDATE tblURL SET processed=? WHERE id=?"
                    k.execute3(sqlupdate,params)

            except Queue.Empty:
                print "thread exiting, id: " + str(thread_id) + "**update**"
                sys.exit()


    # fill the queue with work and block until we are done filling the queue

    producer_thread = Thread(target=putURL)
    producer_thread.start()
    producer_thread.join()

    # we can now start consumers

    for i in range(number_of_consumer_threads):
        getfromDB = Thread(target=getURL, args=(i,))
        getfromDB.start()
        thread_list.append(getfromDB)


    for i in range(number_of_consumer_threads):
        update = Thread(target=updateDB, args=(i,))
        update.start()
        thread_list2.append(update)


    for thread in thread_list:
        thread.join()

    for thread2 in thread_list2:
        thread2.join()
4

0 に答える 0