小编Ski*_*mag的帖子

带装饰器的线程

我正在尝试将线程(使用装饰器)实现到我的应用程序,但无法理解有关锁和管理线程的一些事情.

import threading

def run_in_thread(fn):
    def run(*k, **kw):
        t = threading.Thread(target=fn, args=k, kwargs=kw)
        t.start()
    return run

class A:
    @run_in_thread
    def method1(self):
        for x in range(10000):
            print x


    @run_in_thread
    def method2(self):
        for y in list('wlkefjwfejwiefwhfwfkjshkjadgfjhkewgfjwjefjwe'):
            print y

    def stop_thread(self):
        pass

c = A()
c.method1()
c.method2()
Run Code Online (Sandbox Code Playgroud)
  1. 据我所知,method1和method2不是同步的,而是在锁的帮助下同步实现的东西.如何为我的装饰器功能添加锁?

  2. 如何实现使用装饰器停止长线程的方法?

python multithreading decorator

7
推荐指数
1
解决办法
4649
查看次数

子图背景渐变色

如何在 matplotlib 中创建一些渐变颜色,然后将axisbg我的子图的参数设置为此?

f = plt.figure()
ax = f.add_subplot(111, axisbg='green')
Run Code Online (Sandbox Code Playgroud)

python colors matplotlib

5
推荐指数
1
解决办法
5926
查看次数

标签 统计

python ×2

colors ×1

decorator ×1

matplotlib ×1

multithreading ×1