Python多处理模块的难点

时间:2015-02-18 00:42:47

标签: python multiprocessing

我在我的工作人员函数中temp.connect()收到此错误:

  

ValueError:关闭文件的I / O操作。

当它被抛出时,我没有打开文件,也没有访问它。下面是我创建工人的主要脚本。

import csv
import device
import multiprocessing

with open('FM_IPL_IPs.csv', 'rU') as f:
    reader=csv.reader(f, delimiter=",")
    d=list(reader)

def worker(entry):
    """thread worker function"""
    temp = device.Device(entry[0], entry[1], entry[2])
    temp.connect()
    temp.testAll()
    return

jobs = []
for i in range(0, len(d)):
    if d[i][2]=="WD510U" or d[i][2]=="WD620U" or d[i][2]=="LDT461":
        p = multiprocessing.Process(target=worker, args=(d[i],))
        jobs.append(p)
        p.start()

device.py看起来像这样(为了简洁我删除了内部。)

class Device():
    def __init__(self, roomName, ip, model):
        self.model = model
        self.ip = ip
        self.roomName = roomName
        self.codes = deviceModelconfigs.setCodes(self.model)
        self.powerStatus = 'na'
        self.signalStatus = 'na'
        self.networkStatus = 'off'
    def connect(self):
        self.child = pexpect.spawn('telnet '+ self.ip + ' 2001')
    def sendMessage(self):
        print ("result")
    def testPower(self)
        return stuff
    def testSignal(child)
        return stuff
    def testAll(self):
       self.powerStatus = Device.testPower(self)
       self.signalStatus = Device.testSignal(self)
       Device.sendMessage(self)
       self.child.terminate(True)

更新:为其中一个工人添加堆栈跟踪。

Process Process-127:
Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
    fd = sys.__stdin__.fileno()
ValueError: I/O operation on closed file
    self.run()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/process.py", line 114, in run
    self._target(*self._args, **self._kwargs)
  File "DeviceWatch.py", line 12, in worker
    temp.connect()
  File "/Users/jdschuma/GitHubIntel/Episkey/device.py", line 18, in connect
    self.child = pexpect.spawn('telnet '+ self.ip + ' 2001')
  File "/Library/Python/2.7/site-packages/pexpect/__init__.py", line 493, in __init__

0 个答案:

没有答案