<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#cccccc">
<tt><br>
<br>
On 07/26/2010 09:52 PM, Tomas Pelka wrote:</tt>
<blockquote cite="mid:4C4DE78D.10401@gmail.com" type="cite">
<meta http-equiv="content-type"
content="text/html; charset=ISO-8859-1">
<tt>Zdravim vsechny,<br>
<br>
mam potize s exportovanim objektu pres manager z modulu multiprocess,
priklad:<br>
<br>
Worker.py:<br>
###################################<br>
from multiprocessing import Process<br>
from multiprocessing.managers import BaseManager<br>
import pcapy<br>
from impacket.ImpactDecoder import EthDecoder<br>
<br>
__all__ = ['Worker']<br>
<br>
class Worker(Process):<br>
'''<br>
Class for sniffing packets, runnig as root<br>
'''<br>
<br>
public = ['go', 'terminate']<br>
<br>
def __init__(self):<br>
super(Worker, self).__init__()<br>
self.iface = ''<br>
self.expr = ''<br>
self.pcap = ''<br>
# define packet decoder<br>
self.decoder = EthDecoder()<br>
# key for queue daemon, remotely on localhost:5000<br>
self._keyQ = '10b222970537b97919db36ec757370d2'<br>
class QueueManager(BaseManager): pass<br>
QueueManager.register('get_dataQueue')<br>
self._m = QueueManager(address=('127.0.0.1', 5000),
authkey=self._keyQ)<br>
self._m.connect()<br>
self.dataQueue = self._m.get_dataQueue()<br>
def go(self, iface, expr):<br>
'''<br>
start sniffer<br>
'''<br>
print "Starting sniffer"<br>
self.iface = iface<br>
self.expr = expr<br>
super(Worker, self).start()<br>
def terminate(self):<br>
'''<br>
terminate sniffer<br>
'''<br>
super(Worker, self).terminate()<br>
def run(self):<br>
print "sniffing ..."<br>
print self.iface<br>
print self.expr<br>
self.pcap = pcapy.open_live(self.iface, 1500, 1, 0)<br>
self.pcap.setfilter(self.expr)<br>
self.pcap.loop(0, self.__packetHandler)<br>
print "... done"<br>
def __packetHandler(self, hdr, data):<br>
'''<br>
handles packets and put them in to the queue<br>
'''<br>
print "Handling packets"<br>
#print data<br>
print "Queue size: %i" % self.dataQueue.qsize()<br>
print self.decoder.decode(data)<br>
self.dataQueue.put(data)<br>
<br>
Export objektu (Worker):<br>
</tt><tt>###################################<br>
from Worker import Worker<br>
<br>
class SniffManager(BaseManager): pass<br>
SniffManager.register('Worker', callable=Worker)<br>
Sm = SniffManager(address=('127.0.0.1', 5001),
authkey='f1f16683f3e0208131b46d37a79c8921')<br>
Ss = Sm.get_server()<br>
Ss.serve_forever()<br>
<br>
<br>
Volani metod objektu, vzdalene:<br>
</tt><tt>###################################<br>
</tt><tt># get remote object<br>
class WorkerManager(BaseManager): pass<br>
WorkerManager.register('Worker')<br>
w = WorkerManager(address=('127.0.0.1', 5001), authkey=</tt><tt>'f1f16683f3e0208131b46d37a79c8921'</tt><tt>)<br>
w.connect()<br>
worker = w.Worker() #TOHLE FUNGUJE JAK MA</tt><tt><br>
<br>
ale<br>
<br>
worker.terminate()<br>
<br>
File "/home/tom/web2py/applications/init/controllers/sniffer.py", line
143, in index<br>
worker.terminate()<br>
File "<string>", line 2, in terminate<br>
File "/usr/lib/python2.6/multiprocessing/managers.py", line 740, in
_callmethod<br>
raise convert_to_error(kind, result)<br>
AttributeError: 'NoneType' object has no attribute 'terminate'<br>
<br>
Zarazi me ze go() funguje a terminate() nikoliv. Lokalne funfuje vse
tak jak ma.<br>
<br>
Diky za rady.<br>
</tt></blockquote>
<tt><br>
Nejzvlastnejsi mi prijde to ze </tt><tt>super(Worker,
self).terminate(), tedy </tt><tt>super(Worker, self) je podle pythonu </tt><tt>NoneType.</tt>
<pre class="moz-signature" cols="72"><tt>--
Tomas Pelka</tt></pre>
</body>
</html>