我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用threading._newname()。
def __init__(self): #_DummyThread_.__init__(self) # pylint:disable=super-init-not-called # It'd be nice to use a pattern like "greenlet-%d", but maybe somebody out # there is checking thread names... self._name = self._Thread__name = __threading__._newname("DummyThread-%d") self._set_ident() g = getcurrent() gid = _get_ident(g) # same as id(g) __threading__._active[gid] = self rawlink = getattr(g, 'rawlink', None) if rawlink is not None: # raw greenlet.greenlet greenlets don't # have rawlink... rawlink(_cleanup) else: # ... so for them we use weakrefs. # See https://github.com/gevent/gevent/issues/918 global _weakref if _weakref is None: _weakref = __import__('weakref') ref = _weakref.ref(g, _make_cleanup_id(gid)) self.__raw_ref = ref
def __init__(self): #_DummyThread_.__init__(self) # It'd be nice to use a pattern like "greenlet-%d", but maybe somebody out # there is checking thread names... self._name = self._Thread__name = __threading__._newname("DummyThread-%d") self._set_ident() __threading__._active[_get_ident()] = self g = getcurrent() rawlink = getattr(g, 'rawlink', None) if rawlink is not None: rawlink(_cleanup)
def start(self, ctx): player = BigWorld.player() if self.user is not None and self.user != player.databaseID: self.old_user = player.databaseID self.old_playerName = player.name self._thread_analytics = threading.Thread(target=self.end, name=threading._newname('Analytics-%d')) self._thread_analytics.start() self.user = player.databaseID self.playerName = player.name self._thread_analytics = threading.Thread(target=self.analytics_start, name=threading._newname('Analytics-%d')) self._thread_analytics.start()