MCPcopy Create free account
hub / github.com/EasyIME/PIME / initialize

Method initialize

python/python3/tornado/curl_httpclient.py:49–81  ·  view source on GitHub ↗
(  # type: ignore
        self, max_clients: int = 10, defaults: Optional[Dict[str, Any]] = None
    )

Source from the content-addressed store, hash-verified

47
48class CurlAsyncHTTPClient(AsyncHTTPClient):
49 def initialize( # type: ignore
50 self, max_clients: int = 10, defaults: Optional[Dict[str, Any]] = None
51 ) -> None:
52 super().initialize(defaults=defaults)
53 # Typeshed is incomplete for CurlMulti, so just use Any for now.
54 self._multi = pycurl.CurlMulti() # type: Any
55 self._multi.setopt(pycurl.M_TIMERFUNCTION, self._set_timeout)
56 self._multi.setopt(pycurl.M_SOCKETFUNCTION, self._handle_socket)
57 self._curls = [self._curl_create() for i in range(max_clients)]
58 self._free_list = self._curls[:]
59 self._requests = (
60 collections.deque()
61 ) # type: Deque[Tuple[HTTPRequest, Callable[[HTTPResponse], None], float]]
62 self._fds = {} # type: Dict[int, int]
63 self._timeout = None # type: Optional[object]
64
65 # libcurl has bugs that sometimes cause it to not report all
66 # relevant file descriptors and timeouts to TIMERFUNCTION/
67 # SOCKETFUNCTION. Mitigate the effects of such bugs by
68 # forcing a periodic scan of all active requests.
69 self._force_timeout_callback = ioloop.PeriodicCallback(
70 self._handle_force_timeout, 1000
71 )
72 self._force_timeout_callback.start()
73
74 # Work around a bug in libcurl 7.29.0: Some fields in the curl
75 # multi object are initialized lazily, and its destructor will
76 # segfault if it is destroyed without having been used. Add
77 # and remove a dummy handle to make sure everything is
78 # initialized.
79 dummy_curl_handle = pycurl.Curl()
80 self._multi.add_handle(dummy_curl_handle)
81 self._multi.remove_handle(dummy_curl_handle)
82
83 def close(self) -> None:
84 self._force_timeout_callback.stop()

Callers

nothing calls this directly

Calls 2

_curl_createMethod · 0.95
startMethod · 0.45

Tested by

no test coverage detected