Debian Codegraph @

doc/docstrings/share.rst

raw
1 CurlShare(detach_on_close=True) -> New CurlShare object
2
3 Creates a new :ref:`curlshareobject` which corresponds to a
4 ``CURLSH`` handle in libcurl. CurlShare objects is what you pass as an
5 argument to the SHARE option on :ref:`Curl objects <curlobject>`.
6
7 The ``CurlShare`` object can be used as a context manager. Exiting the
8 context calls ``close()``.
9
10 When a ``CurlShare`` is closed, its behavior depends on the value of
11 ``detach_on_close``.
12
13 Example::
14
15 with pycurl.CurlShare(detach_on_close=True) as s:
16 curl.setopt(pycurl.SHARE, s)
17 # perform operations
18 # the CurlShare is closed and the Curl object has been detached
19
20 :param bool detach_on_close:
21 Controls how associated :ref:`Curl objects <curlobject>` are handled
22 when the ``CurlShare`` is closed.
23
24 If ``True`` (default), all live ``Curl`` objects associated with the
25 share are automatically detached when ``close()`` is called or when
26 exiting the context manager. Detaching clears the ``SHARE`` option on
27 each ``Curl`` object, but does **not** close them. The caller remains
28 responsible for managing the lifetime of the ``Curl`` objects.
29
30 If ``False``, calling ``close()`` (or exiting the context manager)
31 while there are still ``Curl`` objects associated with the share
32 raises an exception. In this mode, the caller must explicitly remove
33 or close all associated ``Curl`` objects before closing the
34 ``CurlShare``.
35
36 .. warning::
37
38 Detaching ``Curl`` objects from a ``CurlShare`` is **not thread-safe**
39 with respect to those ``Curl`` objects.
40
41 The caller is responsible for ensuring proper synchronization when
42 using ``CurlShare`` and ``Curl`` objects across multiple threads.