池中的Seaborn / Matplotlib-X服务器“:1”上的致命IO错误11(资源暂时不可用)

时间:2019-05-06 14:42:55

标签: python matplotlib seaborn

当我尝试使用Seaborn / Matplotlib在池中创建地块时,程序冻结很困难。单独在池中运行代码是可以的,但是如果在运行之前生成代码的其他代码,则会出错并导致程序挂起(请参见下面的错误输出)。这段代码是一个非常简化的示例,其中我设法部分复制了该错误,但是当我在实际项目中运行该错误时,我的整个计算机都死机了,我必须登录到新会话并杀死所有python3才能解冻。我使用的数据集和使用的程序非常复杂,因此我希望此代码示例足够。错误消息似乎与X显示服务器有关,所以我认为这是相同的问题。

如果我在不调用函数的情况下运行make_boxplot函数,则它运行良好,反之亦然,但是如果我在同一脚本中一起运行它们,则会发生以下所示的错误。

可能是什么原因造成的?从输出来看,它似乎挂在对plt.figure的调用上。

import matplotlib.pyplot as plt
from multiprocessing import Pool
import os
import seaborn as sns
import pandas as pd


def make_figure(name):
    print("making figure " + name)
    fig1 = plt.figure(figsize=(12, 12))
    print("created figure " + name)
    ax = fig1.add_subplot(1, 1, 1)
    ax.figure.savefig("temp_out/" + name + ".png")
    plt.close(fig1)


def make_boxplot():
    fig1 = plt.figure(figsize=(12, 12))
    ax = fig1.add_subplot(1, 1, 1)

    index = ['frank', 'jen', 'cindy', 'jabba']
    a = pd.Series(data=[5, 10, 20, 22], index=index, name='a')
    b = pd.Series(data=[7, 9, 5, 6], index=index, name='b')
    c = pd.Series(data=[3, 2, 1, 4], index=index, name='c')
    df = pd.concat([a, b, c], axis=1)

    # sns.boxplot(data=df, palette="Set3", ax=ax)
    # for item in ax.get_xticklabels():
    #     item.set_rotation(90)
    fig1.savefig("temp_out/" + "my_boxplot.png")
    plt.close(fig1)


if not os.path.exists("temp_out"):
    os.makedirs("temp_out")

make_boxplot()

names = ['bob', 'billy', 'josef', 'jane', 'tarzan', 'phil', 'cindy']

pool = Pool(4)
pool.map_async(make_figure, names)
pool.close()
pool.join()

输出:

making figure bob
making figure billy
making figure josef
making figure jane
XIO:  fatal IO error 0 (Success) on X server ":1"
      after 432 requests (432 known processed) with 25 events remaining.
XIO:  fatal IO error 25 (Inappropriate ioctl for device) on X server ":1"
      after 428 requests (428 known processed) with 25 events remaining.
XIO:  fatal IO error 11 (Resource temporarily unavailable) on X server ":1"
      after 428 requests (428 known processed) with 23 events remaining.
making figure tarzan
making figure phil
making figure cindy
created figure cindy
created figure phil
created figure tarzan

0 个答案:

没有答案