当前位置: 首页>>代码示例>>Python>>正文


Python SyncManager.list方法代码示例

本文整理汇总了Python中multiprocessing.managers.SyncManager.list方法的典型用法代码示例。如果您正苦于以下问题:Python SyncManager.list方法的具体用法?Python SyncManager.list怎么用?Python SyncManager.list使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在multiprocessing.managers.SyncManager的用法示例。


在下文中一共展示了SyncManager.list方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from multiprocessing.managers import SyncManager [as 别名]
# 或者: from multiprocessing.managers.SyncManager import list [as 别名]
    def __init__(self, servo_id):
        self.servo_id = servo_id
        self.angle = Value('f', 0.0)
        self.stop_signal = Value('b', False)

        # http://jtushman.github.io/blog/2014/01/14/python-|-multiprocessing-and-interrupts/
        manager = SyncManager() # instead of regular Manager because we want to ignore kb interrupt
        manager.start(Servo.init_mgr) # start the manager explicitly
        self.command_queue = manager.list([])
        self.current_command = manager.dict()

        self.finished = Value('b', False)
开发者ID:mlensment,项目名称:rebot,代码行数:14,代码来源:servo.py

示例2: SyncManager

# 需要导入模块: from multiprocessing.managers import SyncManager [as 别名]
# 或者: from multiprocessing.managers.SyncManager import list [as 别名]
            sys.stderr.write(e.msg)
            failed = True

        scenarios_to_run = self.sort_scenarios(scenarios_to_run)

        # Explictly starting a sync manager to remain after keyboard interupt, so we can print out the errors
        manager = SyncManager()
        try:

            # shared state
            def mgr_init():
                signal.signal(signal.SIGINT, signal.SIG_IGN)

            manager.start(mgr_init)

            errors = manager.list()
            results = manager.list()
            scenario_queue = manager.list()
            interupted = multiprocessing.Event()

            for s in scenarios_to_run:
                scenario_queue.append(s)

            call_hook("before", "all")

            processes = []
            for i in xrange(self.workers):
                port_number = 8180 + i
                process = multiprocessing.Process(
                    target=process_scenarios, args=(scenario_queue, port_number, results, errors, interupted)
                )
开发者ID:phoebusliang,项目名称:parallel-lettuce,代码行数:33,代码来源:__init__.py

示例3: getSharedLists

# 需要导入模块: from multiprocessing.managers import SyncManager [as 别名]
# 或者: from multiprocessing.managers.SyncManager import list [as 别名]
def getSharedLists():
  manager = SyncManager()
  manager.start(lambda: signal.signal(signal.SIGINT, signal.SIG_IGN))
  return (manager.list(), manager.list())
开发者ID:narfman0,项目名称:cs779,代码行数:6,代码来源:UMChatServer.py

示例4: getImgFile

# 需要导入模块: from multiprocessing.managers import SyncManager [as 别名]
# 或者: from multiprocessing.managers.SyncManager import list [as 别名]
class getImgFile(PostGetter):
	def __init__(self, cookie_file, imgfile_base_path):
		PostGetter.__init__(self, cookie_file)
		self.imgfile_base_path = os.path.expanduser(imgfile_base_path)
		assert os.access(self.imgfile_base_path, os.F_OK) == True

		self.fileext = {'jpeg': 'jpg', 'png': 'png', 'gif': 'gif', 'jpg': 'jpg', 'bmp': 'bmp', 'tiff': 'tif'}
		self.pImg = re.compile(r'<img.*?\s+src\s*=\s*"\s*(?!")(.+?)\s*".*?/>', re.U | re.M | re.S | re.I)
		self.bad_domain = []
		self.use_proxy = []
		self.nms = None
		self.pDomainUseProxy = []
		self.multiprocess_manager = None


	def getImageUrl(self, forum_name, sector_name, id_from=None, nr_limit=None):
		u'''获取 reply里面的 img 链接,并入库
		'''
		cnt, tmpminid, step = 0, 0, 5000
##		forum=Forum.objects.get(name__iexact=forum_name)
		sector = Sector.objects.get(forum__name__iexact=forum_name, name__iexact=sector_name)
		if id_from:
			tmpminid = id_from
			maxid = Reply.objects.filter(post__sector=sector).aggregate(maxid=Max('id'))['maxid']
		elif self.processed_maxid:
			self.logger.info('max id processed last time is %d', self.processed_maxid)
			tmpminid = self.processed_maxid  # 上次处理过的reply的最大id
			maxid = Reply.objects.filter(post__sector=sector).aggregate(maxid=Max('id'))['maxid']
		else:
			tmp = Reply.objects.filter(post__sector=sector).aggregate(minid=Min('id'), maxid=Max('id'))
			tmpminid, maxid = tmp['minid'], tmp['maxid']

		self.logger.info('%s\n\tget img url from %s minid,maxid=%d,%d\n\n', '~~~~'*20, sector_name, tmpminid, maxid)
		itertimes = 0
		while (not nr_limit) or (nr_limit and cnt <= nr_limit):
			self.logger.info('%s%d) cnt=%d, tmpminid=%d %s', '-='*15, itertimes, cnt, tmpminid, '-=' * 15)
			rl = Reply.objects.defer('locate_id', 'author', 'crt_date').filter(
				post__sector = sector, id__gte = tmpminid, id__lt = tmpminid+step).order_by('id').iterator()

			for reply in rl:
				cnt += 1
##				self.logger.info('%d) reply %d',cnt,reply.id)

				if nr_limit and nr_limit <= cnt:
					self.logger.info('to nr_limit ! %d', reply.id)
					break

				self._getImg4Reply(reply)
				self.processed_maxid = reply.id

				if self.exitevent.is_set():
					self.logger.info('got exit signal!')
					break


			if self.exitevent.is_set():
				self.logger.info('got exit signal!')
				break

			if nr_limit and nr_limit <= cnt:
				self.logger.info('to nr_limit !')
				break

			if tmpminid > maxid:
				self.logger.info('to maxid! %d', tmpminid)
				break


			itertimes += 1
			tmpminid += step


	def _getImg4Reply(self, reply):
		u'''从 reply 中 获取 img 链接存入数据库'''
		imglist = self.pImg.findall(reply.content)
		dbg_title_prted = False
		premovetag = re.compile('(<.*?>)', re.M | re.S)
		if imglist:
			for i, x in enumerate(imglist):
##				self.logger.info('\t(%d) %d|%s',i+1,reply.id,x)
				# unquote chars like %E5%88%98%E5%BC%BA
##				x=re.sub('(?:(?:%[0-9A-Fa-f]{2})+)+?',lambda xx:self._tryDecode(urllib.unquote(xx.group().encode('gbk'))),x)
				try:
					x = re.sub('(?:(?:%[0-9A-Za-z]{2,3})+)+?', lambda xx: self._tryDecode(urllib.unquote(xx.group().encode('gbk'))), x)
				except UnicodeDecodeError as e:
					self.logger.info('reply %d except: %s\n\t%s', reply.id, e, x)
					continue

				# exceed db field length limit
				if len(x) > 255:
					self.logger.debug('got long url for reply %d, %d', reply.id, len(x))
					continue

				# remove tag
				x = premovetag.sub('', x)

				# convert related path to absolute path
				sr = urlparse.urlsplit(x)

				if sr.scheme == '':
#.........这里部分代码省略.........
开发者ID:liveonnet,项目名称:postgetter-app,代码行数:103,代码来源:getImg.py

示例5: f

# 需要导入模块: from multiprocessing.managers import SyncManager [as 别名]
# 或者: from multiprocessing.managers.SyncManager import list [as 别名]
#!/usr/bin/env python

from multiprocessing.managers import SyncManager
import sys

def f(d, l):
    d[1] = '1'
    d['2'] = 2
    d[0.25] = None
    l.reverse()

if __name__ == '__main__':
    manager = SyncManager(address=('127.0.0.1', int(sys.argv[1])), authkey='abc')

    manager.connect()

    print manager.list()

    print 'Done'


开发者ID:benthomasson,项目名称:mp,代码行数:21,代码来源:local_manager.py

示例6: f

# 需要导入模块: from multiprocessing.managers import SyncManager [as 别名]
# 或者: from multiprocessing.managers.SyncManager import list [as 别名]
#!/usr/bin/env python

from multiprocessing.managers import SyncManager

def f(d, l):
    d[1] = '1'
    d['2'] = 2
    d[0.25] = None
    l.reverse()

if __name__ == '__main__':
    manager = SyncManager(address=('127.0.0.1', 0), authkey='abc')
    server = manager.get_server()

    manager.start()

    d = manager.dict()
    l = manager.list(range(10))

    print server.address
    server.serve_forever()

开发者ID:benthomasson,项目名称:mp,代码行数:23,代码来源:remote_manager.py


注:本文中的multiprocessing.managers.SyncManager.list方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。