Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Process Process-3:
- Traceback (most recent call last):
- File "/usr/local/lib/python3.4/pickle.py", line 272, in _getattribute
- obj = getattr(obj, subpath)
- AttributeError: 'module' object has no attribute 'SRE_Match'
- During handling of the above exception, another exception occurred:
- Traceback (most recent call last):
- File "/usr/local/lib/python3.4/pickle.py", line 909, in save_global
- obj2 = _getattribute(module, name, allow_qualname=self.proto >= 4)
- File "/usr/local/lib/python3.4/pickle.py", line 275, in _getattribute
- .format(name, obj))
- AttributeError: Can't get attribute 'SRE_Match' on <module '_sre' (built-in)>
- During handling of the above exception, another exception occurred:
- Traceback (most recent call last):
- File "/home/ande/.local/lib/python3.4/site-packages/multiprocess-0.70.4-py3.4-linux-x86_64.egg/multiprocess/process.py", line 254, in _bootstrap
- self.run()
- File "/home/ande/.local/lib/python3.4/site-packages/multiprocess-0.70.4-py3.4-linux-x86_64.egg/multiprocess/process.py", line 93, in run
- self._target(*self._args, **self._kwargs)
- File "./SSHHandlerMin.py", line 41, in testSSH
- mDict[devName] = child
- ...
- #!/usr/local/bin/python3
- import pexpect
- import getpass
- from multiprocess import Process, Manager
- def wLauncher(workerDef, maxWorkers, *args):
- workQueue = args[0]
- wQLen = workQueue.qsize()
- procNum = 0
- if (maxWorkers > wQLen):
- procNum = wQLen
- else:
- procNum = maxWorkers
- #Create Workers
- processes = list()
- for worker in range(procNum):
- workerProcess = Process(target=workerDef, args=(args))
- workerProcess.start()
- processes.append(workerProcess)
- workQueue.put('STOP')
- # Wait for all workers to complete their tasks
- for process in processes:
- process.join()
- def testSSH(*args):
- wQ = args[0]
- user = args[1]
- password = args[2]
- mDict = args[3]
- cmd = args[4]
- for device in iter(wQ.get, 'STOP'):
- child = pexpect.spawn("ssh -t "+user+"@"+device)
- i = child.expect(['assword:', r'yes/no',pexpect.EOF,pexpect.TIMEOUT],timeout=30)
- if i == 0:
- mDict[devName] = child
- elif i == 1:
- mDict[devName] = child
- #__main__
- if __name__ == "__main__":
- username = getpass.getuser()
- passPrompt = username+' password:'
- password = getpass.getpass(passPrompt)
- devName = input('Enter Device Name/IP: ')
- cmd = 'date'
- workQueue = Manager().Queue()
- mDict = Manager().dict()
- deviceList = []
- workQueue.put(devName)
- wLauncher(testSSH,30,workQueue,username,password,mDict,cmd)
- print(mDict)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement