You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\Python27\lib\threading.py", line 801, in __bootstrap_inner
self.run()
File "E:/learn/python/test/thread_local.py", line 15, in run
mydata.x['message'] = self.name
AttributeError: 'thread._local' object has no attribute 'x'
Exception in thread Thread-2:
Traceback (most recent call last):
File "C:\Python27\lib\threading.py", line 801, in __bootstrap_inner
self.run()
File "E:/learn/python/test/thread_local.py", line 15, in run
mydata.x['message'] = self.name
AttributeError: 'thread._local' object has no attribute 'x'
classRequest(threading.local):
""" Represents a single request using thread-local namespace. """defbind(self, environ):
""" Binds the enviroment of the current request to this request handler """self._environ=environself._GET=Noneself._POST=Noneself._GETPOST=Noneself._COOKIES=Noneself.path=self._environ.get('PATH_INFO', '/').strip()
ifnotself.path.startswith('/'):
self.path='/'+self.path#----------------------request=Request()
#----------------------defWSGIHandler(environ, start_response):
"""The bottle WSGI-handler."""globalrequestglobalresponserequest.bind(environ)
response.bind()
try:
handler, args=match_url(request.path, request.method)
ifnothandler:
raiseHTTPError(404, "Not found")
output=handler(**args)
exceptBreakTheBottle, shard:
output=shard.output
The text was updated successfully, but these errors were encountered:
thread local in python
参考 Thread Locals in Python: Mostly easy
线程局部变量
各线程独享自己的变量,但是使用全局变量 mydata
主线程也有自己的线程局部变量
线程 w1,w2 没有 x 属性,子线程与主线程拥有各自的变量
继承 threading.local
应用实例
bottle 0.4.10
The text was updated successfully, but these errors were encountered: