1.0.2版修订版

This commit is contained in:
XiongNeng
2016-01-21 10:40:40 +08:00
parent d31aa5a086
commit 21bb590999
6 changed files with 19 additions and 13 deletions

View File

@@ -15,6 +15,7 @@
例如:
.. code-block:: python
from queue import Queue
from threading import Thread

View File

@@ -16,6 +16,7 @@
是非常容易实现的,示例如下:
.. code-block:: python
import threading
from contextlib import contextmanager
@@ -50,6 +51,7 @@
示例如下:
.. code-block:: python
import threading
x_lock = threading.Lock()
y_lock = threading.Lock()
@@ -78,6 +80,7 @@
假设你的代码是这样写的:
.. code-block:: python
import threading
x_lock = threading.Lock()
y_lock = threading.Lock()
@@ -106,6 +109,7 @@
如果你运行这个版本的代码,必定会有一个线程发生崩溃,异常信息可能像这样:
.. code-block:: python
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/local/lib/python3.3/threading.py", line 639, in _bootstrap_inner
@@ -145,6 +149,7 @@
下面是一个简单的使用死锁避免机制解决“哲学家就餐问题”的实现:
.. code-block:: python
import threading
# The philosopher thread

View File

@@ -46,7 +46,7 @@
其他方法操作被存储为 ``self.local.sock`` 的套接字对象。
有了这些就可以在多线程中安全的使用 ``LazyConnection`` 实例了。例如:
::
.. code-block:: python
from functools import partial
def test(conn):