MCPcopy
hub / github.com/tornadoweb/tornado / ThreadedResolver

Class ThreadedResolver

tornado/netutil.py:501–537  ·  view source on GitHub ↗

Multithreaded non-blocking `Resolver` implementation. The thread pool size can be configured with:: Resolver.configure('tornado.netutil.ThreadedResolver', num_threads=10) .. versionchanged:: 3.1 All ``ThreadedResolvers`` share a single thread pool

Source from the content-addressed store, hash-verified

499
500
501class ThreadedResolver(ExecutorResolver):
502 """Multithreaded non-blocking `Resolver` implementation.
503
504 The thread pool size can be configured with::
505
506 Resolver.configure('tornado.netutil.ThreadedResolver',
507 num_threads=10)
508
509 .. versionchanged:: 3.1
510 All ``ThreadedResolvers`` share a single thread pool, whose
511 size is set by the first one to be created.
512
513 .. deprecated:: 5.0
514 The default `Resolver` now uses `.IOLoop.run_in_executor`; use that instead
515 of this class.
516 """
517
518 _threadpool = None # type: ignore
519 _threadpool_pid = None # type: int
520
521 def initialize(self, num_threads: int = 10) -> None: # type: ignore
522 threadpool = ThreadedResolver._create_threadpool(num_threads)
523 super().initialize(executor=threadpool, close_executor=False)
524
525 @classmethod
526 def _create_threadpool(
527 cls, num_threads: int
528 ) -> concurrent.futures.ThreadPoolExecutor:
529 pid = os.getpid()
530 if cls._threadpool_pid != pid:
531 # Threads cannot survive after a fork, so if our pid isn't what it
532 # was when we created the pool then delete it.
533 cls._threadpool = None
534 if cls._threadpool is None:
535 cls._threadpool = concurrent.futures.ThreadPoolExecutor(num_threads)
536 cls._threadpool_pid = pid
537 return cls._threadpool
538
539
540class OverrideResolver(Resolver):

Callers 3

setUpMethod · 0.90
mainFunction · 0.90

Calls

no outgoing calls

Tested by 2

setUpMethod · 0.72
mainFunction · 0.72