Skip to content

Matplotlib Error: NSWindow drag regions should only be invalidated on the Main Thread! This will throw an exception in the future #10

Closed

Description

@xlisp
matplotlib-clj.core=> (plot-it)
2019-11-15 21:02:28.865 java[21046:1140194] WARNING: NSWindow drag regions should only be invalidated on the Main Thread! This will throw an exception in the future. Called from (
	0   AppKit                              0x00007fff2c69e6ef -[NSWindow(NSWindow_Theme) _postWindowNeedsToResetDragMarginsUnlessPostingDisabled] + 371
	1   AppKit                              0x00007fff2c69bbc1 -[NSWindow _initContent:styleMask:backing:defer:contentView:] + 1416
	2   AppKit                              0x00007fff2c69b633 -[NSWindow initWithContentRect:styleMask:backing:defer:] + 42
	3   _macosx.cpython-37m-darwin.so       0x00000001361646b0 -[Window initWithContentRect:styleMask:backing:defer:withManager:] + 80
	4   _macosx.cpython-37m-darwin.so       0x0000000136167bc7 FigureManager_init + 327
	5   Python                              0x000000012ddba050 wrap_init + 12
	6   Python                              0x000000012dd81407 wrapperdescr_call + 337
	7   Python                              0x000000012dd7b668 _PyObject_FastCallKeywords + 365
	8   Python                              0x000000012de123ad call_function + 746
	9   Python                              0x000000012de0af6f _PyEval_EvalFrameDefault + 7020
	10  Python                              0x000000012dd7bbdd function_code_fastcall + 112
	11  Python                              0x000000012dd7c561 _PyObject_Call_Prepend + 150
	12  Python                              0x000000012ddb9fbe slot_tp_init + 80
	13  Python                              0x000000012ddb6c85 type_call + 178
	14  Python                              0x000000012dd7b668 _PyObject_FastCallKeywords + 365
	15  Python                              0x000000012de123ad call_function + 746
	16  Python                              0x000000012de0af6f _PyEval_EvalFrameDefault + 7020
	17  Python                              0x000000012dd7bbdd function_code_fastcall + 112
	18  Python                              0x000000012de123b4 call_function + 753
	19  Python                              0x000000012de0af6f _PyEval_EvalFrameDefault + 7020
	20  Python                              0x000000012de12c5c _PyEval_EvalCodeWithName + 1857
	21  Python                              0x000000012dd7b42a _PyFunction_FastCallDict + 441
	22  Python                              0x000000012dd7c561 _PyObject_Call_Prepend + 150
	23  Python                              0x000000012dd7b910 PyObject_Call + 136
	24  Python                              0x000000012de0b286 _PyEval_EvalFrameDefault + 7811
	25  Python                              0x000000012de12c5c _PyEval_EvalCodeWithName + 1857
	26  Python                              0x000000012dd7b7c7 _PyFunction_FastCallKeywords + 225
	27  Python                              0x000000012de123b4 call_function + 753
	28  Python                              0x000000012de0b00d _PyEval_EvalFrameDefault + 7178
	29  Python                              0x000000012dd7bbdd function_code_fastcall + 112
	30  Python                              0x000000012de123b4 call_function + 753
	31  Python                              0x000000012de0b00d _PyEval_EvalFrameDefault + 7178
	32  Python                              0x000000012de12c5c _PyEval_EvalCodeWithName + 1857
	33  Python                              0x000000012dd7b7c7 _PyFunction_FastCallKeywords + 225
	34  Python                              0x000000012de123b4 call_function + 753
	35  Python                              0x000000012de0b00d _PyEval_EvalFrameDefault + 7178
	36  Python                              0x000000012de12c5c _PyEval_EvalCodeWithName + 1857
	37  Python                              0x000000012dd7b42a _PyFunction_FastCallDict + 441
	38  jna2771800009792166730.tmp          0x0000000127a9be74 ffi_call_unix64 + 76
	39  ???                                 0x000070000ded2548 0x0 + 123145535956296
)

Activity

  1. xlisp commented on Nov 15, 2019

    @xlisp
    Author
  2. cnuernber commented on Nov 15, 2019

    @cnuernber
    Collaborator

    Hmm. I don't think this is fixable from the outside. Probably you will need to use the canvas renderers for matplotlib or only use it from the main thread, not a repl thread (which would be a shame).

    Good idea for a project though.

  3. xlisp commented on Nov 15, 2019

    @xlisp
    Author

    I run this plot in lein run ,not other thread :

    坚持去λ化(eshell) matplotlib-clj  master $ lein run
    十一月 16, 2019 12:20:10 上午 clojure.tools.logging$eval486$fn__489 invoke
    信息: executing python initialize!
    十一月 16, 2019 12:20:10 上午 clojure.tools.logging$eval486$fn__489 invoke
    信息: Library /usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/libpython3.7m.dylib found at [:system "/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/libpython3.7m.dylib"]
    十一月 16, 2019 12:20:10 上午 clojure.tools.logging$eval486$fn__489 invoke
    信息: Reference thread starting
    2019-11-16 00:20:11.618 java[997:1376858] WARNING: NSWindow drag regions should only be invalidated on the Main Thread! This will throw an exception in the future. Called from (
    	0   AppKit                              0x00007fff2c69e6ef -[NSWindow(NSWindow_Theme) _postWindowNeedsToResetDragMarginsUnlessPostingDisabled] + 371
    	1   AppKit                              0x00007fff2c69bbc1 -[NSWindow _initContent:styleMask:backing:defer:contentView:] + 1416
    	2   AppKit                              0x00007fff2c69b633 -[NSWindow initWithContentRect:styleMask:backing:defer:] + 42
    	3   _macosx.cpython-37m-darwin.so       0x000000012ca016b0 -[Window initWithContentRect:styleMask:backing:defer:withManager:] + 80
    	4   _macosx.cpython-37m-darwin.so       0x000000012ca04bc7 FigureManager_init + 327
    	5   Python                              0x0000000124647050 wrap_init + 12
    	6   Python                              0x000000012460e407 wrapperdescr_call + 337
    	7   Python                              0x0000000124608668 _PyObject_FastCallKeywords + 365
    	8   Python                              0x000000012469f3ad call_function + 746
    	9   Python                              0x0000000124697f6f _PyEval_EvalFrameDefault + 7020
    	10  Python                              0x0000000124608bdd function_code_fastcall + 112
    	11  Python                              0x0000000124609561 _PyObject_Call_Prepend + 150
    	12  Python                              0x0000000124646fbe slot_tp_init + 80
    	13  Python                              0x0000000124643c85 type_call + 178
    	14  Python                              0x0000000124608668 _PyObject_FastCallKeywords + 365
    	15  Python                              0x000000012469f3ad call_function + 746
    	16  Python                              0x0000000124697f6f _PyEval_EvalFrameDefault + 7020
    	17  Python                              0x0000000124608bdd function_code_fastcall + 112
    	18  Python                              0x000000012469f3b4 call_function + 753
    	19  Python                              0x0000000124697f6f _PyEval_EvalFrameDefault + 7020
    	20  Python                              0x000000012469fc5c _PyEval_EvalCodeWithName + 1857
    	21  Python                              0x000000012460842a _PyFunction_FastCallDict + 441
    	22  Python                              0x0000000124609561 _PyObject_Call_Prepend + 150
    	23  Python                              0x0000000124608910 PyObject_Call + 136
    	24  Python                              0x0000000124698286 _PyEval_EvalFrameDefault + 7811
    	25  Python                              0x000000012469fc5c _PyEval_EvalCodeWithName + 1857
    	26  Python                              0x00000001246087c7 _PyFunction_FastCallKeywords + 225
    	27  Python                              0x000000012469f3b4 call_function + 753
    	28  Python                              0x000000012469800d _PyEval_EvalFrameDefault + 7178
    	29  Python                              0x0000000124608bdd function_code_fastcall + 112
    	30  Python                              0x000000012469f3b4 call_function + 753
    	31  Python                              0x000000012469800d _PyEval_EvalFrameDefault + 7178
    	32  Python                              0x000000012469fc5c _PyEval_EvalCodeWithName + 1857
    	33  Python                              0x00000001246087c7 _PyFunction_FastCallKeywords + 225
    	34  Python                              0x000000012469f3b4 call_function + 753
    	35  Python                              0x000000012469800d _PyEval_EvalFrameDefault + 7178
    	36  Python                              0x000000012469fc5c _PyEval_EvalCodeWithName + 1857
    	37  Python                              0x000000012460842a _PyFunction_FastCallDict + 441
    	38  jna2383965882915598410.tmp          0x000000010d842e74 ffi_call_unix64 + 76
    	39  ???                                 0x000070000ee0e578 0x0 + 123145551930744
    )
    

    The Code is here :

    (ns matplotlib-clj.core
      (:require [libpython-clj.python :as py]
                [tech.v2.datatype :as dtype]
                [tech.libs.buffered-image :as bufimg]
                [tech.v2.tensor :as dtt]
                [clojure.java.io :as io]
                [clojure.java.shell :as sh]))
    
    (defn init-macox []
      (alter-var-root
       #'libpython-clj.jna.base/*python-library*
       (constantly "/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/libpython3.7m.dylib"))
      (py/initialize!))
    
    (init-macox)
    
    (def mfig (py/import-module "matplotlib.figure"))
    (def magg (py/import-module "matplotlib.backends.backend_agg"))
    (def np (py/import-module "numpy"))
    (def plt (py/import-module "matplotlib.pyplot"))
    
    (def x (py/call-attr np "linspace" 0 2 100))
    ;;(py/python-type x)
    ;;(py/get-attr x "shape")
    
    (defn plot-it []
      (py/call-attr-kw plt "plot" [x x] {"label" "linear"})
      (py/call-attr-kw plt "plot" [x (py/call-attr x "__pow__" 2)] {"label" "quadratic"})
      (py/call-attr-kw plt "plot" [x (py/call-attr x "__pow__" 3)] {"label" "cubic"})
      (py/call-attr plt "xlabel" "x label")
      (py/call-attr plt "ylabel" "y label")
      (py/call-attr plt "title" "Simple Plot")
      (py/call-attr plt "legend"))
    
    (defn -main [& args]
      (plot-it)
      (py/call-attr plt "show"))
    
  4. cnuernber commented on Nov 15, 2019

    @cnuernber
    Collaborator

    I found a matplotlib issue related to this:

    matplotlib/matplotlib#14304

  5. xlisp commented on Nov 15, 2019

    @xlisp
    Author

    Thanks @cnuernber, I use the WebAgg, it's work :-D

    (def mplot (py/import-module "matplotlib"))
    (py/call-attr mplot "use" "WebAgg")
    

    截屏2019-11-16上午12 55 15

  6. cnuernber commented on Nov 17, 2019

    @cnuernber
    Collaborator

    Nice work!!

    Closing as I believe this is a matplotlib issue and not a libpython-clj issue.

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