关于多线程的一个问题·求助? 400 报错
环境:win2003+mysql5+python2.7
# -*- coding: cp936 -*-
import thread
import MySQLdb
def init():
    global DATABASE_NAME
    DATABASE_NAME = 'chengji'
    global HOST
    HOST = 'localhost'
    global PORT
    PORT = '3306'
    global USER_NAME
    USER_NAME = 'root'
    global PASSWORD
    PASSWORD = 'root'
    global CHAR_SET
    CHAR_SET = 'utf8'
      
#获取数据库连接
def get_conn():
    init()
    return MySQLdb.connect(host = HOST, user = USER_NAME, passwd = PASSWORD, db = DATABASE_NAME, charset = CHAR_SET)
  
#获取cursor
def get_cursor(conn):
    return conn.cursor()
  
#关闭连接
def conn_close(conn):
    if conn != None:
        conn.close()
  
#关闭cursor
def cursor_close(cursor):
    if cursor != None:
        cursor.close()
  
#关闭所有
def close(cursor, conn):
    cursor_close(cursor)
    conn_close(conn)
	
#数据库中表情况
def show_tables():
    sql = 'show tables'
    conn = get_conn()
    cursor = get_cursor(conn)
    result = cursor.execute(sql)
    for row in cursor.fetchall():
        print row[0]
        #table_name = row[0]
def query_data(table):
        #threadLock.acquire()
          
        sql = 'select  * from '+ table +' where fenshu = "90"'
        conn = get_conn()
        cursor = get_cursor(conn)
        result = cursor.execute(sql)
        for row1 in cursor.fetchall():
          #姓名,性别,学号,分数
          print row1[1],row1[2],row1[3],row1[4]
        close(cursor, conn)
        
        #threadLock.release()
       
#threadLock=thread.allocate_lock()
#查询表信息
#def query_chaxun1():
i=0
sql = 'show tables'
conn = get_conn()
cursor = get_cursor(conn)
result = cursor.execute(sql)
for row in cursor.fetchall():
  print row[0]
  # 有多少个表就创建多少新线程(语文 数学 英语 政治 历史 地理 物理 化学 体育)
  i=i+1
  print i
  thread.start_new_thread(query_data(row[0])),(i,)
 
 
 
 
 
 

 
  
 上面的thread.start_new_thread创建线程出错,thread.start_new_thread带的函数不能带参数吗?能的话要怎么写?
  
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
from threading import Thread 
from time import sleep 
def threaded_function(arg,szText): 
    for i in range(arg): 
        szTest = szText + " running\n" 
        print szTest 
        sleep(1) 
if __name__ == "__main__": 
    thread1 = Thread(target = threaded_function, args = (10, 'thread1')) 
    thread2 = Thread(target = threaded_function, args = (10, 'thread2')) 
    thread1.start() 
    thread2.start() 
    thread2.join() 
    thread1.join() 
    print "thread finished...exiting"
#参考:http://stackoverflow.com/questions/2905965/creating-threads-in-python