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


Python concurrent.thread函数代码示例

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


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

示例1: start

def start(address):
    global _running
    if _running:
        raise RuntimeError('trying to start reporter while running')
    logging.info("Starting hawkular reporter")
    concurrent.thread(_run, name='hawkular', args=(address,)).start()
    _running = True
开发者ID:EdDev,项目名称:vdsm,代码行数:7,代码来源:hawkular.py

示例2: __init__

    def __init__(self, irs, log, scheduler):
        """
        Initialize the (single) clientIF instance

        :param irs: a Dispatcher object to be used as this object's irs.
        :type irs: :class:`storage.dispatcher.Dispatcher`
        :param log: a log object to be used for this object's logging.
        :type log: :class:`logging.Logger`
        """
        self.vmContainerLock = threading.Lock()
        self._networkSemaphore = threading.Semaphore()
        self._shutdownSemaphore = threading.Semaphore()
        self.irs = irs
        if self.irs:
            self._contEIOVmsCB = partial(clientIF.contEIOVms, proxy(self))
            self.irs.registerDomainStateChangeCallback(self._contEIOVmsCB)
        self.log = log
        self._recovery = True
        self.channelListener = Listener(self.log)
        self._generationID = str(uuid.uuid4())
        self.mom = None
        self.bindings = {}
        self._broker_client = None
        self._subscriptions = defaultdict(list)
        self._scheduler = scheduler
        if _glusterEnabled:
            self.gluster = gapi.GlusterApi(self, log)
        else:
            self.gluster = None
        try:
            self.vmContainer = {}
            self._hostStats = sampling.HostStatsThread(
                sampling.host_samples)
            self._hostStats.start()
            self.lastRemoteAccess = 0
            self._enabled = True
            self._netConfigDirty = False
            self._prepareMOM()
            secret.clear()
            concurrent.thread(self._recoverThread, name='clientIFinit').start()
            self.channelListener.settimeout(
                config.getint('vars', 'guest_agent_timeout'))
            self.channelListener.start()
            self.threadLocal = threading.local()
            self.threadLocal.client = ''

            host = config.get('addresses', 'management_ip')
            port = config.getint('addresses', 'management_port')

            self._createAcceptor(host, port)
            self._prepareXMLRPCBinding()
            self._prepareJSONRPCBinding()
            self._connectToBroker()
        except:
            self.log.error('failed to init clientIF, '
                           'shutting down storage dispatcher')
            if self.irs:
                self.irs.prepareForShutdown()
            raise
开发者ID:borisroman,项目名称:vdsm,代码行数:59,代码来源:clientIF.py

示例3: __del__

    def __del__(self):
        def finalize(log, owner, taskDir):
            log.warn("Task was autocleaned")
            owner.releaseAll()
            if taskDir is not None:
                getProcPool().fileUtils.cleanupdir(taskDir)

        if not self.state.isDone():
            taskDir = None
            if (self.cleanPolicy == TaskCleanType.auto and
                    self.store is not None):
                taskDir = os.path.join(self.store, self.id)
            concurrent.thread(finalize,
                              args=(self.log, self.resOwner, taskDir)).start()
开发者ID:kanalun,项目名称:vdsm,代码行数:14,代码来源:task.py

示例4: start

 def start(self, blocking):
     if blocking:
         return self._dhclient()
     else:
         t = concurrent.thread(self._dhclient,
                               name='dhclient/%s' % self.iface)
         t.start()
开发者ID:EdDev,项目名称:vdsm,代码行数:7,代码来源:dhclient.py

示例5: __del__

 def __del__(self):
     if self._isValid and self.autoRelease:
         def release(log, namespace, name):
             log.warn("Resource reference was not properly released. "
                      "Autoreleasing.")
             # In Python, objects are refcounted and are deleted immediately
             # when the last reference is freed. This means the __del__
             # method can be called inside of any context. The
             # releaseResource method we use tries to acquire locks. So we
             # might try to acquire the lock in a locked context and reach a
             # deadlock. This is why I need to use a timer. It will defer
             # the operation and use a different context.
             ResourceManager.getInstance().releaseResource(namespace, name)
         concurrent.thread(release, args=(self._log, self.namespace,
                                          self.name)).start()
         self._isValid = False
开发者ID:sshnaidm,项目名称:vdsm,代码行数:16,代码来源:resourceManager.py

示例6: test_non_daemon_thread

 def test_non_daemon_thread(self):
     t = concurrent.thread(lambda: None, daemon=False)
     t.start()
     try:
         self.assertFalse(t.daemon)
     finally:
         t.join()
开发者ID:EdDev,项目名称:vdsm,代码行数:7,代码来源:concurrent_test.py

示例7: test_default_daemon_thread

 def test_default_daemon_thread(self):
     t = concurrent.thread(lambda: None)
     t.start()
     try:
         self.assertTrue(t.daemon)
     finally:
         t.join()
开发者ID:EdDev,项目名称:vdsm,代码行数:7,代码来源:concurrent_test.py

示例8: __init__

    def __init__(self, poolID, maxHostID, inbox, outbox, monitorInterval=2):
        """
        Note: inbox paramerter here should point to the HSM's outbox
        mailbox file, and vice versa.
        """
        self._messageTypes = {}
        # Save arguments
        self._stop = False
        self._stopped = False
        self._poolID = poolID
        tpSize = config.getint('irs', 'thread_pool_size') / 2
        waitTimeout = wait_timeout(monitorInterval)
        maxTasks = config.getint('irs', 'max_tasks')
        self.tp = ThreadPool("mailbox-spm", tpSize, waitTimeout, maxTasks)
        self._inbox = inbox
        if not os.path.exists(self._inbox):
            self.log.error("SPM_MailMonitor create failed - inbox %s does not "
                           "exist" % repr(self._inbox))
            raise RuntimeError("SPM_MailMonitor create failed - inbox %s does "
                               "not exist" % repr(self._inbox))
        self._outbox = outbox
        if not os.path.exists(self._outbox):
            self.log.error("SPM_MailMonitor create failed - outbox %s does "
                           "not exist" % repr(self._outbox))
            raise RuntimeError("SPM_MailMonitor create failed - outbox %s "
                               "does not exist" % repr(self._outbox))
        self._numHosts = int(maxHostID)
        self._outMailLen = MAILBOX_SIZE * self._numHosts
        self._monitorInterval = monitorInterval
        # TODO: add support for multiple paths (multiple mailboxes)
        self._outgoingMail = self._outMailLen * "\0"
        self._incomingMail = self._outgoingMail
        self._inCmd = ['dd',
                       'if=' + str(self._inbox),
                       'iflag=direct,fullblock',
                       'count=1'
                       ]
        self._outCmd = ['dd',
                        'of=' + str(self._outbox),
                        'oflag=direct',
                        'iflag=fullblock',
                        'conv=notrunc',
                        'count=1'
                        ]
        self._outLock = threading.Lock()
        self._inLock = threading.Lock()
        # Clear outgoing mail
        self.log.debug("SPM_MailMonitor - clearing outgoing mail, command is: "
                       "%s", self._outCmd)
        cmd = self._outCmd + ['bs=' + str(self._outMailLen)]
        (rc, out, err) = _mboxExecCmd(cmd, data=self._outgoingMail)
        if rc:
            self.log.warning("SPM_MailMonitor couldn't clear outgoing mail, "
                             "dd failed")

        self._thread = concurrent.thread(
            self.run, name="mailbox-spm", log=self.log)
        self._thread.start()
        self.log.debug('SPM_MailMonitor created for pool %s' % self._poolID)
开发者ID:EdDev,项目名称:vdsm,代码行数:59,代码来源:mailbox.py

示例9: handle_request

 def handle_request(self):
     sock, addr = self.queue.get()
     if sock is self._STOP:
         return
     self.log.info("Starting request handler for %s:%d", addr[0], addr[1])
     t = concurrent.thread(self._process_requests, args=(sock, addr),
                           log=self.log)
     t.start()
开发者ID:EdDev,项目名称:vdsm,代码行数:8,代码来源:http.py

示例10: progress

def progress(op, estimated_size):
    done = threading.Event()
    th = concurrent.thread(volume_progress, args=(op, done, estimated_size))
    th.start()
    try:
        yield th
    finally:
        done.set()
        th.join()
开发者ID:EdDev,项目名称:vdsm,代码行数:9,代码来源:kvm2ovirt.py

示例11: __init__

 def __init__(self, vm, dst='', dstparams='',
              mode=MODE_REMOTE, method=METHOD_ONLINE,
              tunneled=False, dstqemu='', abortOnError=False,
              consoleAddress=None, compressed=False,
              autoConverge=False, recovery=False, **kwargs):
     self.log = vm.log
     self._vm = vm
     self._dst = dst
     self._mode = mode
     if method != METHOD_ONLINE:
         self.log.warning(
             'migration method %s is deprecated, forced to "online"',
             method)
     self._dstparams = dstparams
     self._enableGuestEvents = kwargs.get('enableGuestEvents', False)
     self._machineParams = {}
     # TODO: conv.tobool shouldn't be used in this constructor, the
     # conversions should be handled properly in the API layer
     self._tunneled = conv.tobool(tunneled)
     self._abortOnError = conv.tobool(abortOnError)
     self._consoleAddress = consoleAddress
     self._dstqemu = dstqemu
     self._downtime = kwargs.get('downtime') or \
         config.get('vars', 'migration_downtime')
     self._maxBandwidth = int(
         kwargs.get('maxBandwidth') or
         config.getint('vars', 'migration_max_bandwidth')
     )
     self._autoConverge = conv.tobool(autoConverge)
     self._compressed = conv.tobool(compressed)
     self._incomingLimit = kwargs.get('incomingLimit')
     self._outgoingLimit = kwargs.get('outgoingLimit')
     self.status = {
         'status': {
             'code': 0,
             'message': 'Migration in progress'}}
     # we need to guard against concurrent updates only
     self._lock = threading.Lock()
     self._progress = 0
     self._thread = concurrent.thread(
         self.run, name='migsrc/' + self._vm.id[:8])
     self._preparingMigrationEvt = True
     self._migrationCanceledEvt = threading.Event()
     self._monitorThread = None
     self._destServer = None
     self._convergence_schedule = {
         'init': [],
         'stalling': []
     }
     self._use_convergence_schedule = False
     if 'convergenceSchedule' in kwargs:
         self._convergence_schedule = kwargs.get('convergenceSchedule')
         self._use_convergence_schedule = True
         self.log.debug('convergence schedule set to: %s',
                        str(self._convergence_schedule))
     self._started = False
     self._recovery = recovery
开发者ID:EdDev,项目名称:vdsm,代码行数:57,代码来源:migration.py

示例12: test_pass_args

    def test_pass_args(self):
        self.args = ()

        def run(*args):
            self.args = args

        t = concurrent.thread(run, args=(1, 2, 3))
        t.start()
        t.join()
        self.assertEqual((1, 2, 3), self.args)
开发者ID:EdDev,项目名称:vdsm,代码行数:10,代码来源:concurrent_test.py

示例13: _emit

    def _emit(self, *args, **kwargs):
        self._log.debug("Emitting event")
        with self._syncRoot:
            for funcId, (funcRef, oneshot) in self._registrar.items():
                func = funcRef()
                if func is None or oneshot:
                    del self._registrar[funcId]
                    if func is None:
                        continue
                try:
                    self._log.debug("Calling registered method `%s`", logUtils.funcName(func))
                    if self._sync:
                        func(*args, **kwargs)
                    else:
                        concurrent.thread(func, args=args, kwargs=kwargs).start()
                except:
                    self._log.warn("Could not run registered method because " "of an exception", exc_info=True)

        self._log.debug("Event emitted")
开发者ID:fancyKai,项目名称:vdsm,代码行数:19,代码来源:misc.py

示例14: test_run_callable_in_thread

    def test_run_callable_in_thread(self):
        self.thread = threading.current_thread()

        def run():
            self.thread = threading.current_thread()

        t = concurrent.thread(run)
        t.start()
        t.join()
        self.assertEqual(t, self.thread)
开发者ID:EdDev,项目名称:vdsm,代码行数:10,代码来源:concurrent_test.py

示例15: test_pass_kwargs

    def test_pass_kwargs(self):
        self.kwargs = ()

        def run(**kwargs):
            self.kwargs = kwargs

        kwargs = {'a': 1, 'b': 2}
        t = concurrent.thread(run, kwargs=kwargs)
        t.start()
        t.join()
        self.assertEqual(kwargs, self.kwargs)
开发者ID:EdDev,项目名称:vdsm,代码行数:11,代码来源:concurrent_test.py


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