golden hour
/opt/alt/python311/lib64/python3.11
⬆️ Go Up
Upload
File/Folder
Size
Actions
LICENSE.txt
13.61 KB
Del
OK
__future__.py
5.1 KB
Del
OK
__hello__.py
227 B
Del
OK
__pycache__
-
Del
OK
_aix_support.py
3.31 KB
Del
OK
_bootsubprocess.py
2.61 KB
Del
OK
_collections_abc.py
29.49 KB
Del
OK
_compat_pickle.py
8.56 KB
Del
OK
_compression.py
5.55 KB
Del
OK
_markupbase.py
14.31 KB
Del
OK
_osx_support.py
21.51 KB
Del
OK
_py_abc.py
6.04 KB
Del
OK
_pydecimal.py
223.83 KB
Del
OK
_pyio.py
91.99 KB
Del
OK
_sitebuiltins.py
3.05 KB
Del
OK
_strptime.py
24.58 KB
Del
OK
_sysconfigdata__linux_x86_64-linux-gnu.py
57.93 KB
Del
OK
_sysconfigdata_d_linux_x86_64-linux-gnu.py
57.16 KB
Del
OK
_threading_local.py
7.05 KB
Del
OK
_weakrefset.py
5.75 KB
Del
OK
abc.py
6.38 KB
Del
OK
aifc.py
33.41 KB
Del
OK
antigravity.py
500 B
Del
OK
argparse.py
97.93 KB
Del
OK
ast.py
60 KB
Del
OK
asynchat.py
11.3 KB
Del
OK
asyncio
-
Del
OK
asyncore.py
19.83 KB
Del
OK
base64.py
20.55 KB
Del
OK
bdb.py
31.7 KB
Del
OK
bisect.py
3.06 KB
Del
OK
bz2.py
11.57 KB
Del
OK
cProfile.py
6.21 KB
Del
OK
calendar.py
24.15 KB
Del
OK
cgi.py
33.63 KB
Del
OK
cgitb.py
12.13 KB
Del
OK
chunk.py
5.37 KB
Del
OK
cmd.py
14.52 KB
Del
OK
code.py
10.37 KB
Del
OK
codecs.py
36.28 KB
Del
OK
codeop.py
5.77 KB
Del
OK
collections
-
Del
OK
colorsys.py
3.97 KB
Del
OK
compileall.py
19.78 KB
Del
OK
concurrent
-
Del
OK
config-3.11-x86_64-linux-gnu
-
Del
OK
configparser.py
54.36 KB
Del
OK
contextlib.py
26.77 KB
Del
OK
contextvars.py
129 B
Del
OK
copy.py
8.48 KB
Del
OK
copyreg.py
7.5 KB
Del
OK
crypt.py
3.82 KB
Del
OK
csv.py
15.65 KB
Del
OK
ctypes
-
Del
OK
curses
-
Del
OK
dataclasses.py
57.1 KB
Del
OK
datetime.py
89.68 KB
Del
OK
dbm
-
Del
OK
decimal.py
320 B
Del
OK
difflib.py
81.36 KB
Del
OK
dis.py
28.23 KB
Del
OK
distutils
-
Del
OK
doctest.py
103.81 KB
Del
OK
email
-
Del
OK
encodings
-
Del
OK
ensurepip
-
Del
OK
enum.py
77.72 KB
Del
OK
filecmp.py
9.94 KB
Del
OK
fileinput.py
15.35 KB
Del
OK
fnmatch.py
5.86 KB
Del
OK
fractions.py
28 KB
Del
OK
ftplib.py
34.98 KB
Del
OK
functools.py
37.51 KB
Del
OK
genericpath.py
5.12 KB
Del
OK
getopt.py
7.31 KB
Del
OK
getpass.py
5.85 KB
Del
OK
gettext.py
20.82 KB
Del
OK
glob.py
8.53 KB
Del
OK
graphlib.py
9.43 KB
Del
OK
gzip.py
23.51 KB
Del
OK
hashlib.py
11.49 KB
Del
OK
heapq.py
22.48 KB
Del
OK
hmac.py
7.54 KB
Del
OK
html
-
Del
OK
http
-
Del
OK
imaplib.py
53.92 KB
Del
OK
imghdr.py
3.86 KB
Del
OK
imp.py
10.36 KB
Del
OK
importlib
-
Del
OK
inspect.py
120.53 KB
Del
OK
io.py
4.22 KB
Del
OK
ipaddress.py
79.51 KB
Del
OK
json
-
Del
OK
keyword.py
1.04 KB
Del
OK
lib-dynload
-
Del
OK
lib2to3
-
Del
OK
linecache.py
5.52 KB
Del
OK
locale.py
77.24 KB
Del
OK
logging
-
Del
OK
lzma.py
12.97 KB
Del
OK
mailbox.py
76.98 KB
Del
OK
mailcap.py
9.15 KB
Del
OK
mimetypes.py
22.42 KB
Del
OK
modulefinder.py
23.14 KB
Del
OK
multiprocessing
-
Del
OK
netrc.py
6.77 KB
Del
OK
nntplib.py
40.12 KB
Del
OK
ntpath.py
28.09 KB
Del
OK
nturl2path.py
2.82 KB
Del
OK
numbers.py
10.11 KB
Del
OK
opcode.py
10.2 KB
Del
OK
operator.py
10.71 KB
Del
OK
optparse.py
58.95 KB
Del
OK
os.py
38.6 KB
Del
OK
pathlib.py
47.43 KB
Del
OK
pdb.py
62.68 KB
Del
OK
pickle.py
63.61 KB
Del
OK
pickletools.py
91.66 KB
Del
OK
pipes.py
8.77 KB
Del
OK
pkgutil.py
24.06 KB
Del
OK
platform.py
41.3 KB
Del
OK
plistlib.py
27.92 KB
Del
OK
poplib.py
14.84 KB
Del
OK
posixpath.py
16.67 KB
Del
OK
pprint.py
24.01 KB
Del
OK
profile.py
22.36 KB
Del
OK
pstats.py
28.67 KB
Del
OK
pty.py
6.17 KB
Del
OK
py_compile.py
7.65 KB
Del
OK
pyclbr.py
11.13 KB
Del
OK
pydoc.py
110.02 KB
Del
OK
pydoc_data
-
Del
OK
queue.py
11.23 KB
Del
OK
quopri.py
7.11 KB
Del
OK
random.py
31.41 KB
Del
OK
re
-
Del
OK
reprlib.py
5.31 KB
Del
OK
rlcompleter.py
7.64 KB
Del
OK
runpy.py
12.85 KB
Del
OK
sched.py
6.2 KB
Del
OK
secrets.py
1.98 KB
Del
OK
selectors.py
19.21 KB
Del
OK
shelve.py
8.36 KB
Del
OK
shlex.py
13.18 KB
Del
OK
shutil.py
55.19 KB
Del
OK
signal.py
2.44 KB
Del
OK
site-packages
-
Del
OK
site.py
22.45 KB
Del
OK
smtpd.py
30.44 KB
Del
OK
smtplib.py
44.37 KB
Del
OK
sndhdr.py
7.27 KB
Del
OK
socket.py
36.68 KB
Del
OK
socketserver.py
26.94 KB
Del
OK
sqlite3
-
Del
OK
sre_compile.py
231 B
Del
OK
sre_constants.py
232 B
Del
OK
sre_parse.py
229 B
Del
OK
ssl.py
53.03 KB
Del
OK
stat.py
5.36 KB
Del
OK
statistics.py
46.59 KB
Del
OK
string.py
11.51 KB
Del
OK
stringprep.py
12.61 KB
Del
OK
struct.py
257 B
Del
OK
subprocess.py
86.65 KB
Del
OK
sunau.py
18.05 KB
Del
OK
symtable.py
10.13 KB
Del
OK
sysconfig.py
29.6 KB
Del
OK
tabnanny.py
11.05 KB
Del
OK
tarfile.py
109.33 KB
Del
OK
telnetlib.py
22.75 KB
Del
OK
tempfile.py
31.13 KB
Del
OK
textwrap.py
19.26 KB
Del
OK
this.py
1003 B
Del
OK
threading.py
56.87 KB
Del
OK
timeit.py
13.21 KB
Del
OK
token.py
2.33 KB
Del
OK
tokenize.py
25.72 KB
Del
OK
tomllib
-
Del
OK
trace.py
28.51 KB
Del
OK
traceback.py
39.6 KB
Del
OK
tracemalloc.py
17.62 KB
Del
OK
tty.py
879 B
Del
OK
types.py
9.83 KB
Del
OK
typing.py
118.12 KB
Del
OK
unittest
-
Del
OK
urllib
-
Del
OK
uu.py
7.17 KB
Del
OK
uuid.py
26.95 KB
Del
OK
venv
-
Del
OK
warnings.py
20.62 KB
Del
OK
wave.py
21.31 KB
Del
OK
weakref.py
21.01 KB
Del
OK
webbrowser.py
24.56 KB
Del
OK
wsgiref
-
Del
OK
xdrlib.py
5.84 KB
Del
OK
xml
-
Del
OK
xmlrpc
-
Del
OK
zipapp.py
7.36 KB
Del
OK
zipfile.py
92.23 KB
Del
OK
zipimport.py
30.17 KB
Del
OK
zoneinfo
-
Del
OK
Edit: _threading_local.py
"""Thread-local objects. (Note that this module provides a Python version of the threading.local class. Depending on the version of Python you're using, there may be a faster one available. You should always import the `local` class from `threading`.) Thread-local objects support the management of thread-local data. If you have data that you want to be local to a thread, simply create a thread-local object and use its attributes: >>> mydata = local() >>> mydata.number = 42 >>> mydata.number 42 You can also access the local-object's dictionary: >>> mydata.__dict__ {'number': 42} >>> mydata.__dict__.setdefault('widgets', []) [] >>> mydata.widgets [] What's important about thread-local objects is that their data are local to a thread. If we access the data in a different thread: >>> log = [] >>> def f(): ... items = sorted(mydata.__dict__.items()) ... log.append(items) ... mydata.number = 11 ... log.append(mydata.number) >>> import threading >>> thread = threading.Thread(target=f) >>> thread.start() >>> thread.join() >>> log [[], 11] we get different data. Furthermore, changes made in the other thread don't affect data seen in this thread: >>> mydata.number 42 Of course, values you get from a local object, including a __dict__ attribute, are for whatever thread was current at the time the attribute was read. For that reason, you generally don't want to save these values across threads, as they apply only to the thread they came from. You can create custom local objects by subclassing the local class: >>> class MyLocal(local): ... number = 2 ... def __init__(self, /, **kw): ... self.__dict__.update(kw) ... def squared(self): ... return self.number ** 2 This can be useful to support default values, methods and initialization. Note that if you define an __init__ method, it will be called each time the local object is used in a separate thread. This is necessary to initialize each thread's dictionary. Now if we create a local object: >>> mydata = MyLocal(color='red') Now we have a default number: >>> mydata.number 2 an initial color: >>> mydata.color 'red' >>> del mydata.color And a method that operates on the data: >>> mydata.squared() 4 As before, we can access the data in a separate thread: >>> log = [] >>> thread = threading.Thread(target=f) >>> thread.start() >>> thread.join() >>> log [[('color', 'red')], 11] without affecting this thread's data: >>> mydata.number 2 >>> mydata.color Traceback (most recent call last): ... AttributeError: 'MyLocal' object has no attribute 'color' Note that subclasses can define slots, but they are not thread local. They are shared across threads: >>> class MyLocal(local): ... __slots__ = 'number' >>> mydata = MyLocal() >>> mydata.number = 42 >>> mydata.color = 'red' So, the separate thread: >>> thread = threading.Thread(target=f) >>> thread.start() >>> thread.join() affects what we see: >>> mydata.number 11 >>> del mydata """ from weakref import ref from contextlib import contextmanager __all__ = ["local"] # We need to use objects from the threading module, but the threading # module may also want to use our `local` class, if support for locals # isn't compiled in to the `thread` module. This creates potential problems # with circular imports. For that reason, we don't import `threading` # until the bottom of this file (a hack sufficient to worm around the # potential problems). Note that all platforms on CPython do have support # for locals in the `thread` module, and there is no circular import problem # then, so problems introduced by fiddling the order of imports here won't # manifest. class _localimpl: """A class managing thread-local dicts""" __slots__ = 'key', 'dicts', 'localargs', 'locallock', '__weakref__' def __init__(self): # The key used in the Thread objects' attribute dicts. # We keep it a string for speed but make it unlikely to clash with # a "real" attribute. self.key = '_threading_local._localimpl.' + str(id(self)) # { id(Thread) -> (ref(Thread), thread-local dict) } self.dicts = {} def get_dict(self): """Return the dict for the current thread. Raises KeyError if none defined.""" thread = current_thread() return self.dicts[id(thread)][1] def create_dict(self): """Create a new dict for the current thread, and return it.""" localdict = {} key = self.key thread = current_thread() idt = id(thread) def local_deleted(_, key=key): # When the localimpl is deleted, remove the thread attribute. thread = wrthread() if thread is not None: del thread.__dict__[key] def thread_deleted(_, idt=idt): # When the thread is deleted, remove the local dict. # Note that this is suboptimal if the thread object gets # caught in a reference loop. We would like to be called # as soon as the OS-level thread ends instead. local = wrlocal() if local is not None: dct = local.dicts.pop(idt) wrlocal = ref(self, local_deleted) wrthread = ref(thread, thread_deleted) thread.__dict__[key] = wrlocal self.dicts[idt] = wrthread, localdict return localdict @contextmanager def _patch(self): impl = object.__getattribute__(self, '_local__impl') try: dct = impl.get_dict() except KeyError: dct = impl.create_dict() args, kw = impl.localargs self.__init__(*args, **kw) with impl.locallock: object.__setattr__(self, '__dict__', dct) yield class local: __slots__ = '_local__impl', '__dict__' def __new__(cls, /, *args, **kw): if (args or kw) and (cls.__init__ is object.__init__): raise TypeError("Initialization arguments are not supported") self = object.__new__(cls) impl = _localimpl() impl.localargs = (args, kw) impl.locallock = RLock() object.__setattr__(self, '_local__impl', impl) # We need to create the thread dict in anticipation of # __init__ being called, to make sure we don't call it # again ourselves. impl.create_dict() return self def __getattribute__(self, name): with _patch(self): return object.__getattribute__(self, name) def __setattr__(self, name, value): if name == '__dict__': raise AttributeError( "%r object attribute '__dict__' is read-only" % self.__class__.__name__) with _patch(self): return object.__setattr__(self, name, value) def __delattr__(self, name): if name == '__dict__': raise AttributeError( "%r object attribute '__dict__' is read-only" % self.__class__.__name__) with _patch(self): return object.__delattr__(self, name) from threading import current_thread, RLock
Save