• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python concurrent.thread函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: __init__

 def __init__(self, log):
     self.log = log
     self._quit = False
     self._epoll = select.epoll()
     self._channels = {}
     self._unconnected = {}
     self._update_lock = threading.Lock()
     self._add_channels = {}
     self._del_channels = []
     self._timeout = None
     self._thread = concurrent.thread(
         self.run, name='vmchannels'
     )
开发者ID:EdDev,项目名称:vdsm,代码行数:13,代码来源:vmchannels.py


示例17: test_close

    def test_close(self):
        reactor = Reactor()
        thread = concurrent.thread(reactor.process_requests, name="test ractor")
        thread.start()
        s1, s2 = socket.socketpair()
        with closing(s2):
            disp = reactor.create_dispatcher(s1, impl=TestingImpl())
            reactor.stop()

        thread.join(timeout=1)

        self.assertTrue(disp.closing)
        self.assertFalse(reactor._wakeupEvent.closing)
开发者ID:nirs,项目名称:vdsm,代码行数:13,代码来源:better_asyncore_tests.py


示例18: itmap

def itmap(func, iterable, maxthreads=UNLIMITED_THREADS):
    """
    Make an iterator that computes the function using
    arguments from the iterable. It works similar to tmap
    by running each operation in a different thread, this
    causes the results not to return in any particular
    order so it's good if you don't care about the order
    of the results.
    maxthreads stands for maximum threads that we can initiate simultaneosly.
               If we reached to max threads the function waits for thread to
               finish before initiate the next one.
    """
    if maxthreads < 1 and maxthreads != UNLIMITED_THREADS:
        raise ValueError("Wrong input to function itmap: %s", maxthreads)

    respQueue = queue.Queue()

    def wrapper(value):
        try:
            respQueue.put(func(value))
        except Exception as e:
            respQueue.put(e)

    threadsCreated = 0
    threadsCount = 0
    for arg in iterable:
        if maxthreads != UNLIMITED_THREADS:
            if maxthreads == 0:
                # This not supposed to happened. If it does, it's a bug.
                # maxthreads should get to 0 only after threadsCount is
                # greater than 1
                if threadsCount < 1:
                    raise RuntimeError("No thread initiated")
                else:
                    yield respQueue.get()
                    # if yield returns one thread stopped, so we can run
                    # another thread in queue
                    maxthreads += 1
                    threadsCount -= 1

        name = "itmap/%d" % threadsCreated
        t = concurrent.thread(wrapper, args=(arg,), name=name)
        t.start()
        threadsCreated += 1
        threadsCount += 1
        maxthreads -= 1

    # waiting for rest threads to end
    for i in range(threadsCount):
        yield respQueue.get()
开发者ID:EdDev,项目名称:vdsm,代码行数:50,代码来源:misc.py


示例19: __init__

 def __init__(self, domainMonitor, sdUUID, hostId, interval):
     self.thread = concurrent.thread(self._run, logger=self.log.name)
     self.domainMonitor = domainMonitor
     self.stopEvent = threading.Event()
     self.domain = None
     self.sdUUID = sdUUID
     self.hostId = hostId
     self.interval = interval
     self.nextStatus = Status(actual=False)
     self.status = FrozenStatus(self.nextStatus)
     self.isIsoDomain = None
     self.isoPrefix = None
     self.lastRefresh = time.time()
     self.refreshTime = \
         config.getint("irs", "repo_stats_cache_refresh_timeout")
开发者ID:borisroman,项目名称:vdsm,代码行数:15,代码来源:monitor.py


示例20: __init__

 def __init__(self, groups=frozenset(), timeout=None, silent_timeout=False):
     self._time_start = None
     self._timeout = timeout
     self._silent_timeout = silent_timeout
     if groups:
         unknown_groups = frozenset(groups).difference(frozenset(_GROUPS))
         if unknown_groups:
             raise AttributeError('Invalid groups: %s' % (unknown_groups,))
         self._groups = groups
     else:
         self._groups = _GROUPS.keys()
     self._queue = queue.Queue()
     self._scan_thread = concurrent.thread(self._scan)
     self._scanning_started = threading.Event()
     self._scanning_stopped = threading.Event()
开发者ID:andrewlukoshko,项目名称:vdsm,代码行数:15,代码来源:monitor.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python config.get函数代码示例发布时间:2022-05-26
下一篇:
Python time.monotonic_time函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap