Skip to content

Cannot use threading with Mac OSX Backend #5251

Description

@nils-werner

The following does not work on Mac OSX:

from __future__ import division

import threading
import time
import sys
import numpy as np
import matplotlib
matplotlib.use('MacOSX')

import matplotlib.pyplot as plt


class async_worker(threading.Thread):
    def __init__(self, fig, axis):
        threading.Thread.__init__(self)
        self.fig = fig
        self.axis = axis

    def run(self):
        i = 0
        while True:
            print "Run thread %d" % i
            sys.stdout.flush()
            i += 1
            time.sleep(0.1)


def main():
    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1)
    ax.plot(np.random.rand(251, 1))

    async_worker(fig, ax).start()
    plt.show()


if __name__ == "__main__":
    main()

I expect to see "Run thread" repeated every 0.1 seconds, no matter if I interact with the plot or not. Instead I only see it repeat when I click and drag around in the MPL figure.

When switching to matplotlib.use('TkAgg'), the second thread runs as expected.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions