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


Python threadable.synchronize函数代码示例

本文整理汇总了Python中twisted.python.threadable.synchronize函数的典型用法代码示例。如果您正苦于以下问题:Python synchronize函数的具体用法?Python synchronize怎么用?Python synchronize使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: str_or_none

            (external, reason, ssid, complete, results) = res[0]
            external_idstring = str_or_none(external)
            reason = str_or_none(reason)
            complete = bool(complete)
            return (external_idstring, reason, ssid, complete, results)
        return None # shouldn't happen

    def get_pending_brids_for_builder(self, buildername):
        return self.runInteractionNow(self._txn_get_pending_brids_for_builder,
                                      buildername)
    def _txn_get_pending_brids_for_builder(self, t, buildername):
        # "pending" means unclaimed and incomplete. When a build is returned
        # to the pool (self.resubmit_buildrequests), the claimed_at= field is
        # reset to zero.
        t.execute(self.quoteq("SELECT id FROM buildrequests"
                              " WHERE buildername=? AND"
                              "  complete=0 AND claimed_at=0"),
                  (buildername,))
        return [brid for (brid,) in t.fetchall()]

    # test/debug methods

    def has_pending_operations(self):
        return bool(self._pending_operation_count)

    def setChangeCacheSize(self, max_size):
        self._change_cache.setMaxSize(max_size)


threadable.synchronize(DBConnector)
开发者ID:dionorgua,项目名称:buildbot,代码行数:30,代码来源:connector.py

示例2: view_resumeProducing

		self.request = None

	# Remotely relay producer interface.

	def view_resumeProducing(self, issuer):
		self.resumeProducing()

	def view_pauseProducing(self, issuer):
		self.pauseProducing()

	def view_stopProducing(self, issuer):
		self.stopProducing()

	synchronized = ['resumeProducing', 'stopProducing']

threadable.synchronize(MPEGTSTransfer)

class DynamTSTransfer(pb.Viewable):
	def __init__(self, path, pmt, *pids):
		self.path = path
		#log.msg("DynamTSTransfer: pmt: %s, pids: %s" % (pmt, pids))
		self.pmt = pmt
		self.pids = pids
		self.didpat = False

	def resumeProducing(self):
		if not self.request:
			return

		repcnt = 0
		data = self.fp.read(min(abstract.FileDescriptor.bufferSize,
开发者ID:intenso,项目名称:PyMedS-ng,代码行数:31,代码来源:mpegtsmod.py

示例3: aMethod

from twisted.python import threadable

class TestObject:
    synchronized = ['aMethod']

    x = -1
    y = 1

    def aMethod(self):
        for i in range(10):
            self.x, self.y = self.y, self.x
            self.z = self.x + self.y
            assert self.z == 0, "z == %d, not 0 as expected" % (self.z,)

threadable.synchronize(TestObject)

class SynchronizationTests(unittest.SynchronousTestCase):
    def setUp(self):
        """
        Reduce the CPython check interval so that thread switches happen much
        more often, hopefully exercising more possible race conditions.  Also,
        delay actual test startup until the reactor has been started.
        """
        if _PY3:
            if getattr(sys, 'getswitchinterval', None) is not None:
                self.addCleanup(sys.setswitchinterval, sys.getswitchinterval())
                sys.setswitchinterval(0.0000001)
        else:
            if getattr(sys, 'getcheckinterval', None) is not None:
                self.addCleanup(sys.setcheckinterval, sys.getcheckinterval())
开发者ID:JohnDoes95,项目名称:project_parser,代码行数:30,代码来源:test_threadable.py

示例4: pauseProducing

            except StopIteration:
                self.request.unregisterProducer()
                self.request.finish()
                self.request = None
            else:
                self.request.write(chunk)

    def pauseProducing(self):
        pass

    def stopProducing(self):
        self.request = None

    synchronized = ['resumeProducing', 'stopProducing']

threadable.synchronize(QuixoteProducer)


def run(create_publisher, host='', port=80):
    """Runs a Twisted HTTP server server that publishes a Quixote
    application."""
    publisher = create_publisher()
    factory = QuixoteFactory(publisher)
    reactor.listenTCP(port, factory, interface=host)
    reactor.run()


if __name__ == '__main__':
    from quixote.server.util import main
    main(run)
开发者ID:pganti,项目名称:micheles,代码行数:30,代码来源:twisted_server.py

示例5: len

                                   # code is broken.
            self.lock.release()
        else:
            self.failures += 1

        # This is just the only way I can think of to wake up the test
        # method.  It doesn't actually have anything to do with the
        # test.
        self.lock.acquire()
        self.runs.append(None)
        if len(self.runs) == self.N:
            self.waiting.release()
        self.lock.release()

    synchronized = ["run"]
threadable.synchronize(Synchronization)



class ThreadPoolTestCase(unittest.SynchronousTestCase):
    """
    Test threadpools.
    """

    def getTimeout(self):
        """
        Return number of seconds to wait before giving up.
        """
        return 5 # Really should be order of magnitude less

开发者ID:AlexanderHerlan,项目名称:syncpy,代码行数:29,代码来源:test_threadpool.py

示例6: view_resumeProducing

		self.request = None

	# Remotely relay producer interface.

	def view_resumeProducing(self, issuer):
		self.resumeProducing()

	def view_pauseProducing(self, issuer):
		self.pauseProducing()

	def view_stopProducing(self, issuer):
		self.stopProducing()

	synchronized = ['resumeProducing', 'stopProducing']

threadable.synchronize(IterTransfer)

class IterGenResource(resource.Resource):
	isLeaf = True

	def __init__(self, itergen):
		resource.Resource.__init__(self)

		self.itergen = itergen

	def render(self, request):
		request.setHeader('content-type', 'video/mpeg')

		if request.method == 'HEAD':
			return ''
开发者ID:intenso,项目名称:PyMedS-ng,代码行数:30,代码来源:dvd.py

示例7: list

        return list(bsids)

    def get_buildset_info(self, bsid):
        bset_obj = rpc.RpcProxy('software_dev.commit')
        res = bset_obj.read(bsid, ['external_idstring', 'reason', 'complete', 'results'])
        if res:
            external_idstring = res['external_idstring'] or None
            reason = res['reason'] or None
            complete = bool(res['complete'])
            return (external_idstring, reason, bsid, complete, res['results'])
        return None # shouldn't happen

    def get_pending_brids_for_builder(self, buildername):
        breq_obj = rpc.RpcProxy('software_dev.commit')
        
        bids = breq_obj.search([('buildername', '=',  buildername), 
                        ('complete', '=', False), ('claimed_at', '=', False)])
        
        return list(bids)

    # test/debug methods

    def has_pending_operations(self):
        return bool(self._pending_operation_count)

    def setChangeCacheSize(self, max_size):
        self._change_cache.setMaxSize(max_size)

threadable.synchronize(OERPConnector)
#eof
开发者ID:chengdh,项目名称:openerp-buildbot,代码行数:30,代码来源:connector.py

示例8: get

        self._cached_ids = [] # = [LRU .. MRU]

    def get(self, id):
        thing = self._cache.get(id, None)
        if thing is not None:
            self._cached_ids.remove(id)
            self._cached_ids.append(id)
        return thing
    __getitem__ = get

    def add(self, id, thing):
        if id in self._cache:
            self._cached_ids.remove(id)
            self._cached_ids.append(id)
            return
        while len(self._cached_ids) >= self._max_size:
            del self._cache[self._cached_ids.pop(0)]
        self._cache[id] = thing
        self._cached_ids.append(id)
    __setitem__ = add

threadable.synchronize(LRUCache)


def none_or_str(x):
    """Cast X to a str if it is not None"""
    if x is not None and not isinstance(x, str):
        return str(x)
    return x

开发者ID:frelo,项目名称:buildbot,代码行数:29,代码来源:__init__.py

示例9: int

            try:
                counter = int(name.split(".")[-1])
                if counter:
                    result.append(counter)
            except ValueError:
                pass
        result.sort()
        return result

    def __getstate__(self):
        state = BaseLogFile.__getstate__(self)
        del state["size"]
        return state


threadable.synchronize(LogFile)


class DailyLogFile(BaseLogFile):
    """A log file that is rotated daily (at or after midnight localtime)
    """

    def _openFile(self):
        BaseLogFile._openFile(self)
        self.lastDate = self.toDate(os.stat(self.path)[8])

    def shouldRotate(self):
        """Rotate when the date has changed since last write"""
        return self.toDate() > self.lastDate

    def toDate(self, *args):
开发者ID:jsober,项目名称:twisted,代码行数:31,代码来源:logfile.py

示例10: fix_path

        DailyLogFile._openFile(self)

    def fix_path(self):
        file_name = '%04d-%02d-%02d' % (self.toDate())
        self.path = os.path.join(self.directory, "%s-%s" % (self.name, file_name))

    def rotate(self):
        if not (os.access(self.directory, os.W_OK)):return
        next_date = self.toDate(os.stat(self.path)[8])
        print 'Close Old LogFile(%s) ' % self.path
        self._file.close()
        self._openFile()
        self.lastDate = next_date
        print 'Open  New LogFile(%s)' % self.path
        
threadable.synchronize(EveryDayLogFile)

SERVER_NOTE = logging.FATAL + 10

log_inited = False
_log = None

_stdout = sys.stdout
_stderr = sys.stderr

AFTER_LOG_OPER = None
LOG_TAG = None

def init_log_path(dir_name, name_pre):
    global log_inited
    global _log
开发者ID:ezioruan,项目名称:common,代码行数:31,代码来源:twisted_log.py

示例11: view_resumeProducing

        self.streamIter = None

    # Remotely relay producer interface.

    def view_resumeProducing(self, issuer):
        self.resumeProducing()

    def view_pauseProducing(self, issuer):
        self.pauseProducing()

    def view_stopProducing(self, issuer):
        self.stopProducing()

    synchronized = ['resumeProducing', 'stopProducing']

threadable.synchronize(TWProducer)



class QuixoteFactory(http.HTTPFactory):

    def __init__(self, publisher):
        self.publisher = publisher
        http.HTTPFactory.__init__(self, None)

    def buildProtocol(self, addr):
        p = http.HTTPFactory.buildProtocol(self, addr)
        p.requestFactory = QuixoteTWRequest
        return p

开发者ID:carmackjia,项目名称:douban-quixote,代码行数:29,代码来源:twisted_http.py

示例12: int

        for name in glob.glob("%s.*" % self.path):
            try:
                counter = int(name.split('.')[-1])
                if counter:
                    result.append(counter)
            except ValueError:
                pass
        result.sort()
        return result

    def __getstate__(self):
        state = BaseLogFile.__getstate__(self)
        del state["lastDate"]
        return state

threadable.synchronize(WaderLogFile)


def _get_application():
    """
    Factory function that returns an Application object.
    If the object does not exist then it creates a new Application object.
    (Internal use only).
    """
    global _application
    if _application is not None:
        return _application

    _application = Application(consts.APP_NAME)
    logfile = WaderLogFile(consts.LOG_NAME, consts.LOG_DIR,
                                            maxRotatedFiles=consts.LOG_NUMBER)
开发者ID:andrewbird,项目名称:wader,代码行数:31,代码来源:startup.py

示例13: fetch_genres

		raise NotImplementedError, failure

	def fetch_genres(self):
		if self.havegenre:
			return self.genre
		if not self.fetchinggenre:
			# Need to start fetching
			getPage(self.genre_url.encode('ascii')) \
			    .addCallbacks(self.gotGenre, self.errGenre)
			self.fetchinggenre = defer.Deferred()
		# Always raise this if we are waiting.
		raise self.fetchinggenre

	synchronized = ['fetch_genres', 'gotGenre', ]

threadable.synchronize(GenreFeedAsync)

class ShoutcastFeedAsync(feeds.ShoutcastFeed):
	def __init__(self, *args, **kwargs):
		feeds.ShoutcastFeed.__init__(self, *args, **kwargs)

		self.shout_url = \
		    'http://www.shoutcast.com/sbin/newxml.phtml?genre=' + \
		    self.genre

		self.havestations = False
		self.fetchingstations = None

	def gotStations(self, page):
		self.stations = page
		self.havestations = True
开发者ID:intenso,项目名称:PyMedS-ng,代码行数:31,代码来源:shoutcast.py

示例14: _runWithCallback

    def _runWithCallback(self, callback, errback, func, args, kwargs):
        try:
            result = apply(func, args, kwargs)
        except Exception, e:
            task.schedule(errback, e)
        else:
            task.schedule(callback, result)
    
    def dispatchWithCallback(self, owner, callback, errback, func, *args, **kw):
        """Dispatch a function, returning the result to a callback function.
        
        The callback function will be called in the main event loop thread.
        """
        self.dispatchApply(owner, callback, errback, func, args, kw)

    def dispatchApply(self, owner, callback, errback, func, args, kw):
        self.dispatch(owner, self._runWithCallback, callback, errback, func, args, kw)


theDispatcher = ThreadDispatcher(0)

def dispatchApply(callback, errback, func, args, kw):
    theDispatcher.dispatchApply(log.logOwner.owner(), callback, errback, func, args, kw)

def dispatch(callback, errback, func, *args, **kw):
    dispatchApply(callback, errback, func, args, kw)

main.addShutdown(theDispatcher.stop)

threadable.synchronize(ThreadDispatcher)
开发者ID:lhl,项目名称:songclub,代码行数:30,代码来源:threadtask.py

示例15: Counter

import pickle, time

from twisted.trial import unittest
from twisted.python import log, threadable
from twisted.internet import reactor, interfaces

class Counter(log.Logger):    
    index = 0
    
    def add(self):
        self.index = self.index + 1
    
    synchronized = ["add"]

threadable.synchronize(Counter)

class ThreadPoolTestCase(unittest.TestCase):
    """Test threadpools."""

    def testPersistence(self):
        tp = threadpool.ThreadPool(7, 20)
        tp.start()
        time.sleep(0.1)
        self.assertEquals(len(tp.threads), 7)
        self.assertEquals(tp.min, 7)
        self.assertEquals(tp.max, 20)
        
        # check that unpickled threadpool has same number of threads
        s = pickle.dumps(tp)
        tp2 = pickle.loads(s)
开发者ID:pwarren,项目名称:AGDeviceControl,代码行数:30,代码来源:test_threadpool.py


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