question about multiprocessing

2010-06-20 Thread hywhy


first sorry for my poor english. Is there any problem in the follow code?
thanks!


from multiprocessing.managers import BaseManager 
import Queue   

class CrawlerManager(BaseManager):
pass

downloader_queue = Queue.Queue()
   
downloader_queue.put('hello')

CrawlerManager.register('get_downloader_queue', callable=lambda:
downloader_queue)

mgr = CrawlerManager()
mgr.start()

q = mgr.get_downloader_queue()



error:

pickle.PicklingError: Can't pickle  at 0x00C02F70>: it's
not found as __parents_main__.
Traceback (most recent call last):

print q.get()
-- 
View this message in context: 
http://old.nabble.com/question-about-multiprocessing-tp28940614p28940614.html
Sent from the Python - python-list mailing list archive at Nabble.com.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: question about multiprocessing

2010-06-24 Thread hywhy

thanks,friend!
I wanna use Queue to share objects,but on windows, the multiprocessing
module can‘t do this。 Is there any way to solve this problem!
thanks
-- 
View this message in context: 
http://old.nabble.com/question-about-multiprocessing-tp28940614p28982744.html
Sent from the Python - python-list mailing list archive at Nabble.com.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: question about multiprocessing

2010-06-26 Thread hywhy

thanks,firend. I have a try with SyncManager, Is there any problem in my
code?


from multiprocessing.managers import SyncManager,BaseProxy

import multiprocessing
import Queue   

class ResourceController(object):

def __init__(self):
self.text = 'Hello  world!'
self.queue = multiprocessing.Queue()

self.queue.put('I am queue')

def say(self):
print self.text

def get_queue(self):
return self.queue

class ResourceProxy(BaseProxy):

def say_hello(self):
return self._callmethod('say')

def get_queue(self):
return self._callmethod('get_queue')


class CrawlerManager(SyncManager):

def __init__(self):
SyncManager.__init__(self)
self.register('ResourceController', ResourceController,
ResourceProxy)



if __name__ == '__main__':
cm = CrawlerManager()
cm.start()

rc = cm.ResourceController()
rc.say_hello()
q = rc.get_queue()

print q.get()

-- 
View this message in context: 
http://old.nabble.com/question-about-multiprocessing-tp28940614p29000781.html
Sent from the Python - python-list mailing list archive at Nabble.com.

-- 
http://mail.python.org/mailman/listinfo/python-list