在Apache

时间:2016-09-22 14:47:00

标签: python windows apache flask wsgi

我遇到在wsgi / Apache托管时在Windows上运行ptyhon中的多个进程的问题。通过从命令提示符运行它,在Flask自托管环境中运行它时,相同的代码可以正常工作。

用于调用方法的代码段:

     # Start the processer
        print("Before creating Process")
        p = Process(target=self.worker, args=(task_reader, result_writer, pipeline_location_chunks[process_number],))
        print("Before starting process")

        #p= Process(target=self.Testworker)
        p.start()

工人方法的定义

def worker(self, task_reader, result_writer, pipeline_locations):
        """This is the method run by each sub-process. When initialized it loads its share of
        classifier pipelines into memory and sends True back to the start function to inform
        that it is ready for classification tasks"""
        # Load the pipelines in a dictionary with category number as key
        print("In Worker method")
        pipelines = {}
        for pipeline_location in pipeline_locations:
            category = int(pipeline_location.strip('.p'))
            pipelines[category] = pickle.load(open(self.pipeline_dir + pipeline_location, 'rb+'))

        # Inform the start function that this process's pipelines are done loading
        print("before sending")
        result_writer.send(True)

        # Wait for tasks. If a new task (sent by the classify function) is received,
        # run each pipeline's decision function and append it to a list of results
        # to send back to the classify function
        while True:
            # Get tasks (if any) from this process's task queue. If there are none, this process's
            # flow blocks here until there is a task available
            new_task = task_reader.recv()
            print("after receiving")
            results = []
            for category, pipeline in pipelines.items():
                result = pipeline.decision_function(new_task)
                tup = (category, result[0])
                results.append(tup)
            # Send the list of results back to the classify function
            result_writer.send(results)

当我在apache中运行此代码时,它会启动该进程,但不会打印在worker方法中添加的第一行。我故意添加了这个日志记录,以验证多处理工作正常。请告诉我如何使其正常运行,因为我需要在生产中进行部署。

环境详情: 烧瓶0.11 Python 3.5 Apache 2.4.23(64位)

0 个答案:

没有答案