/
opt
/
alt
/
python33
/
lib64
/
python3.3
/
/opt/alt/python33/lib64/python3.3
mkdir
upload
Name
Size
Mode
Actions
collections/
-
0755
rm
concurrent/
-
0755
rm
config-3.3m/
-
0755
rm
ctypes/
-
0755
rm
curses/
-
0755
rm
dbm/
-
0755
rm
distutils/
-
0755
rm
email/
-
0755
rm
encodings/
-
0755
rm
html/
-
0755
rm
http/
-
0755
rm
idlelib/
-
0755
rm
importlib/
-
0755
rm
json/
-
0755
rm
lib-dynload/
-
0755
rm
lib2to3/
-
0755
rm
logging/
-
0755
rm
multiprocessing/
-
0755
rm
plat-linux/
-
0755
rm
pydoc_data/
-
0755
rm
site-packages/
-
0755
rm
sqlite3/
-
0755
rm
test/
-
0755
rm
unittest/
-
0755
rm
urllib/
-
0755
rm
venv/
-
0755
rm
wsgiref/
-
0755
rm
xml/
-
0755
rm
xmlrpc/
-
0755
rm
__pycache__/
-
0755
rm
abc.py
8057
0644
edit
dl
rm
aifc.py
31054
0644
edit
dl
rm
antigravity.py
475
0644
edit
dl
rm
argparse.py
89069
0644
edit
dl
rm
ast.py
12142
0644
edit
dl
rm
asynchat.py
11588
0644
edit
dl
rm
asyncore.py
20753
0644
edit
dl
rm
base64.py
13986
0755
edit
dl
rm
bdb.py
21894
0644
edit
dl
rm
binhex.py
13708
0644
edit
dl
rm
bisect.py
2595
0644
edit
dl
rm
bz2.py
18473
0644
edit
dl
rm
calendar.py
22940
0644
edit
dl
rm
cgi.py
35554
0755
edit
dl
rm
cgitb.py
12041
0644
edit
dl
rm
chunk.py
5377
0644
edit
dl
rm
cmd.py
14860
0644
edit
dl
rm
code.py
10030
0644
edit
dl
rm
codecs.py
35956
0644
edit
dl
rm
codeop.py
5994
0644
edit
dl
rm
colorsys.py
3691
0644
edit
dl
rm
compileall.py
9743
0644
edit
dl
rm
configparser.py
49437
0644
edit
dl
rm
contextlib.py
9125
0644
edit
dl
rm
copy.py
8991
0644
edit
dl
rm
copyreg.py
6611
0644
edit
dl
rm
cProfile.py
6361
0755
edit
dl
rm
crypt.py
1879
0644
edit
dl
rm
csv.py
16185
0644
edit
dl
rm
datetime.py
74954
0644
edit
dl
rm
decimal.py
228558
0644
edit
dl
rm
difflib.py
82519
0644
edit
dl
rm
dis.py
10134
0644
edit
dl
rm
doctest.py
102933
0644
edit
dl
rm
dummy_threading.py
2815
0644
edit
dl
rm
filecmp.py
9597
0644
edit
dl
rm
fileinput.py
14256
0644
edit
dl
rm
fnmatch.py
3163
0644
edit
dl
rm
formatter.py
14930
0644
edit
dl
rm
fractions.py
23033
0644
edit
dl
rm
ftplib.py
40253
0644
edit
dl
rm
functools.py
13596
0644
edit
dl
rm
genericpath.py
3093
0644
edit
dl
rm
getopt.py
7488
0644
edit
dl
rm
getpass.py
5793
0644
edit
dl
rm
gettext.py
20637
0644
edit
dl
rm
glob.py
2838
0644
edit
dl
rm
gzip.py
24403
0644
edit
dl
rm
hashlib.py
6193
0644
edit
dl
rm
heapq.py
17997
0644
edit
dl
rm
hmac.py
4440
0644
edit
dl
rm
imaplib.py
50111
0644
edit
dl
rm
imghdr.py
3528
0644
edit
dl
rm
imp.py
9727
0644
edit
dl
rm
inspect.py
78960
0644
edit
dl
rm
io.py
3280
0644
edit
dl
rm
ipaddress.py
70303
0644
edit
dl
rm
keyword.py
2060
0755
edit
dl
rm
linecache.py
3864
0644
edit
dl
rm
locale.py
93215
0644
edit
dl
rm
lzma.py
17454
0644
edit
dl
rm
macpath.py
5617
0644
edit
dl
rm
macurl2path.py
2732
0644
edit
dl
rm
mailbox.py
79093
0644
edit
dl
rm
mailcap.py
7437
0644
edit
dl
rm
mimetypes.py
20735
0644
edit
dl
rm
modulefinder.py
23198
0644
edit
dl
rm
netrc.py
5747
0644
edit
dl
rm
nntplib.py
42786
0644
edit
dl
rm
ntpath.py
20437
0644
edit
dl
rm
nturl2path.py
2396
0644
edit
dl
rm
numbers.py
10398
0644
edit
dl
rm
opcode.py
5098
0644
edit
dl
rm
optparse.py
60346
0644
edit
dl
rm
os.py
34779
0644
edit
dl
rm
os2emxpath.py
4659
0644
edit
dl
rm
pdb.py
60653
0755
edit
dl
rm
pickle.py
47858
0644
edit
dl
rm
pickletools.py
81349
0644
edit
dl
rm
pipes.py
8916
0644
edit
dl
rm
pkgutil.py
21539
0644
edit
dl
rm
platform.py
50742
0755
edit
dl
rm
plistlib.py
14777
0644
edit
dl
rm
poplib.py
11372
0644
edit
dl
rm
posixpath.py
14254
0644
edit
dl
rm
pprint.py
12700
0644
edit
dl
rm
profile.py
21448
0755
edit
dl
rm
pstats.py
26372
0644
edit
dl
rm
pty.py
5055
0644
edit
dl
rm
pyclbr.py
13438
0644
edit
dl
rm
pydoc.py
101644
0755
edit
dl
rm
py_compile.py
6717
0644
edit
dl
rm
queue.py
8835
0644
edit
dl
rm
quopri.py
7315
0755
edit
dl
rm
random.py
25660
0644
edit
dl
rm
re.py
14973
0644
edit
dl
rm
reprlib.py
5110
0644
edit
dl
rm
rlcompleter.py
5526
0644
edit
dl
rm
runpy.py
10413
0644
edit
dl
rm
sched.py
6399
0644
edit
dl
rm
shelve.py
8243
0644
edit
dl
rm
shlex.py
11502
0644
edit
dl
rm
shutil.py
39147
0644
edit
dl
rm
site.py
21971
0644
edit
dl
rm
smtpd.py
30207
0755
edit
dl
rm
smtplib.py
38021
0755
edit
dl
rm
sndhdr.py
6219
0644
edit
dl
rm
socket.py
14913
0644
edit
dl
rm
socketserver.py
24196
0644
edit
dl
rm
sre_compile.py
16345
0644
edit
dl
rm
sre_constants.py
7231
0644
edit
dl
rm
sre_parse.py
30212
0644
edit
dl
rm
ssl.py
24478
0644
edit
dl
rm
stat.py
4304
0644
edit
dl
rm
string.py
9410
0644
edit
dl
rm
stringprep.py
12917
0644
edit
dl
rm
struct.py
238
0644
edit
dl
rm
subprocess.py
67578
0644
edit
dl
rm
sunau.py
17523
0644
edit
dl
rm
symbol.py
2051
0755
edit
dl
rm
symtable.py
7383
0644
edit
dl
rm
sysconfig.py
25174
0644
edit
dl
rm
tabnanny.py
11410
0755
edit
dl
rm
tarfile.py
88864
0755
edit
dl
rm
telnetlib.py
27349
0644
edit
dl
rm
tempfile.py
23013
0644
edit
dl
rm
textwrap.py
16488
0644
edit
dl
rm
this.py
1003
0644
edit
dl
rm
threading.py
45641
0644
edit
dl
rm
timeit.py
12395
0755
edit
dl
rm
token.py
3034
0644
edit
dl
rm
tokenize.py
24876
0644
edit
dl
rm
trace.py
31487
0755
edit
dl
rm
traceback.py
11982
0644
edit
dl
rm
tty.py
879
0644
edit
dl
rm
types.py
3167
0644
edit
dl
rm
uu.py
6766
0755
edit
dl
rm
uuid.py
22349
0644
edit
dl
rm
warnings.py
13825
0644
edit
dl
rm
wave.py
18579
0644
edit
dl
rm
weakref.py
11495
0644
edit
dl
rm
webbrowser.py
22913
0755
edit
dl
rm
xdrlib.py
5381
0644
edit
dl
rm
zipfile.py
66424
0644
edit
dl
rm
_compat_pickle.py
4338
0644
edit
dl
rm
_dummy_thread.py
4769
0644
edit
dl
rm
_markupbase.py
14598
0644
edit
dl
rm
_osx_support.py
18855
0644
edit
dl
rm
_pyio.py
72905
0644
edit
dl
rm
_strptime.py
21674
0644
edit
dl
rm
_sysconfigdata.py
21056
0644
edit
dl
rm
_threading_local.py
7410
0644
edit
dl
rm
_weakrefset.py
5705
0644
edit
dl
rm
__future__.py
4584
0644
edit
dl
rm
__phello__.foo.py
64
0644
edit
dl
rm
Edit:
/opt/alt/python33/lib64/python3.3/_threading_local.py
(7410B)
"""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 ... initialized = False ... def __init__(self, **kw): ... if self.initialized: ... raise SystemError('__init__ called too many times') ... self.initialized = True ... 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'), ('initialized', True)], 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
cmd:
run