无法将python文件(使用多线程)导入另一个python文件

问题描述 投票:0回答:1

我在导入python文件时遇到了问题(python文件包含一个多线程类,它读取数据库中的每一行,并为每一行启动一个线程。)

当我尝试从另一个python文件导入此文件时,没有任何事情发生。在内核中,内核看起来好像挂了(空白)。 **基本上代码在导入行之后没有进展。它正在那里受到打击。有什么建议或帮助吗?

伪代码(我要导入的文件)

import time
import MySQLdb   
import threading

class Job(threading.Thread):
      def __init__(self, x, conn, sleepBuffer=0):
      threading.Thread.__init__(self)    
      self.x = x
      self.conn = conn
      self.sleepBuffer = sleepBuffer

      def run(self):    
        self.session = Session(hostname=self.x)
        self.job(self.x)

      def job(self, x):            
    ######### do something and update the database columns. It keeps running continuously and updates the table periodically. 

db  = MySQLdb.connect(####user,password,dbname)
cur = db.cursor()                
cur.execute("select x from TABLE where x = %s" %(x))
rows = cur.fetchall()
threads = []
for row in rows:
    conn = MySQLdb.connect((####user,password,dbname)

    time.sleep(1)
    thread = Job(row[0], conn)
    thread.start()

    threads.append(thread) 

for thread in threads:
    thread.join()

我正在尝试使用“import filename”行导入文件。我想可能是我做错了,并检查了其他导入方式。但它们都不起作用。

python multithreading flask-sqlalchemy
1个回答
0
投票

你试过这个..

import sys
sys.path.insert(0, '/path/to/application/app/folder')

import file
© www.soinside.com 2019 - 2024. All rights reserved.