Python:_主线程';对象没有属性'_州';

Python:_主线程';对象没有属性'_州';,python,multithreading,python-multiprocessing,Python,Multithreading,Python Multiprocessing,嘿,伙计们,我正在创建一个应用程序,它接收用户的请求。服务器端的主要类是控制器。我在init期间生成了一个线程,它会一直积极地侦听来自客户端的请求(我需要在这里生成一个线程) 一旦我收到一个请求,我会查看请求的类型并调用一个函数来处理它 在该功能中,我希望创建多个流程来有效利用我的8个核心 代码如下:- class Controller(app_manager.RyuApp): OFP_VERSIONS = [ofproto_v1_3.OFP_VERSION] def __in

嘿,伙计们,我正在创建一个应用程序,它接收用户的请求。服务器端的主要类是控制器。我在init期间生成了一个线程,它会一直积极地侦听来自客户端的请求(我需要在这里生成一个线程)

一旦我收到一个请求,我会查看请求的类型并调用一个函数来处理它

在该功能中,我希望创建多个流程来有效利用我的8个核心

代码如下:-

class Controller(app_manager.RyuApp):
    OFP_VERSIONS = [ofproto_v1_3.OFP_VERSION]

    def __init__(self, *args, **kwargs):
        self.datapaths={}
        self.monitor_thread=hub.spawn(self._monitor)
        super(Controller, self).__init__( *args, **kwargs)

    def _monitor(self):
        global connstream   
        while True:
            #Get Connection from client

            data = connstream.read(15000)
            data=eval(data)
            print "Recieved a request from the client:-",data
            for key,value in data.iteritems():
                type=int(key)
                request=value
                if type==4:
                    self.get_route(type,request,connstream)


    def get_route(self,type,request,connection):
            global get_route_result
            cities=request['Cities']
            number_of_cities=request['Number_of_Cities']
            city_count=0
            processes=[]
            pool = mp.Pool(processes=8)
            for city,destination_ip in cities.iteritems():
                 args=(type,destination_ip)
                 processes.append(args)
                 city_count=city_count+1
                 if city_count==number_of_cities:
                      break 
            pool.map(self.get_route_process,processes)  




    def get_route_process(self,HOST,destination):
          #Do Something
但我得到的错误是:-

Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 810, in    __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 763, in run
self.__target(*self.__args, **self.__kwargs)
File "/usr/lib/python2.7/multiprocessing/pool.py", line 325, in _handle_workers
while thread._state == RUN or (pool._cache and thread._state != TERMINATE):
AttributeError: '_MainThread' object has no attribute '_state'

简而言之,我创建了一个线程,它试图创建多个进程,但代码失败了

很难看出失败的地方是什么,因为您的回溯实际上并不涉及您向我们展示的程序的任何部分。@Gerrat程序在初始化期间创建的线程中失败。这可能是因为我试图从一个线程创建多个进程。
Controller
中的监视功能似乎没有使用superlcass中的任何内容。难道你不能生成两个实例,一个
监视器
和一个
app\u manager.RyuApp
(可能需要一些定制)的实例并将RyuApp的实例传递给该监视器吗?在
\uu init\uuuuuuuu
中引用的
hub
是什么/在哪里,但没有在任何地方显示?@gerrathub来自python模块。我正在使用RYU,它是一个openflow控制器。基本上我可以在交换机上安装规则。