Code Monkey home page Code Monkey logo

Comments (8)

jjtolton avatar jjtolton commented on July 19, 2024

I was able to reproduce this on Linux with version 1.36. Very interesting! Digging in a little deeper.

from libpython-clj.

cnuernber avatar cnuernber commented on July 19, 2024

Agreed, this is an interesting one. I wonder if the sys module expects a stack frame and is just quietly exiting early when it doesn't get one.

from libpython-clj.

jjtolton avatar jjtolton commented on July 19, 2024

I can confirm that this is something related to require-python.

This works (does not throw error):

(require '[libpython-clj.python :as py])

(py/initialize! :no-io-redirect? true)

(require '[libpython-clj.require :refer [require-python]])

(py/import-module "sys")
;;=> :ok 

This will reproduce @mharju 's error

(require '[libpython-clj.python :as py])

(py/initialize! :no-io-redirect? true)

(require '[libpython-clj.require :refer [require-python]])

(require-python 'sys)
;;=> Failed to get a pyobject pointer from object.

from libpython-clj.

jjtolton avatar jjtolton commented on July 19, 2024

A stupid hack would be we could just automatically call import-python when you (require 'libpython-clj.require) if it turns out that this is isolated to the sys module.

from libpython-clj.

cnuernber avatar cnuernber commented on July 19, 2024

Well, first let's get a bit more bug reporting discipline going :-).

The stack trace of the error is:

                  base.clj:   52  libpython-clj.jna.base/ensure-pyobj
                  base.clj:   48  libpython-clj.jna.base/ensure-pyobj
                   err.clj:  184  libpython-clj.jna.concrete.err/PyErr-Restore
                   err.clj:  184  libpython-clj.jna.concrete.err/PyErr-Restore
                object.clj:  907  libpython-clj.python.object/python->jvm-iterator/next-fn
                 Atom.java:   93  clojure.lang.Atom/swapVals
                  core.clj: 2363  clojure.core/swap-vals!
                  core.clj: 2357  clojure.core/swap-vals!
                object.clj:  920  libpython-clj.python.object/python/reify
                   RT.java:  523  clojure.lang.RT$4/invoke
              LazySeq.java:   42  clojure.lang.LazySeq/sval
              LazySeq.java:   51  clojure.lang.LazySeq/seq
                   RT.java:  535  clojure.lang.RT/seq
                  core.clj:  137  clojure.core/seq
                  core.clj: 2746  clojure.core/map/fn
              LazySeq.java:   42  clojure.lang.LazySeq/sval
              LazySeq.java:   51  clojure.lang.LazySeq/seq
          ChunkedCons.java:   59  clojure.lang.ChunkedCons/chunkedNext
          ChunkedCons.java:   43  clojure.lang.ChunkedCons/next
                   RT.java:  713  clojure.lang.RT/next
          SeqIterator.java:   41  clojure.lang.SeqIterator/hasNext
                   RT.java:  522  clojure.lang.RT$4/invoke
              LazySeq.java:   42  clojure.lang.LazySeq/sval
              LazySeq.java:   51  clojure.lang.LazySeq/seq
                   RT.java:  535  clojure.lang.RT/seq
                  core.clj:  137  clojure.core/seq
                  core.clj: 2746  clojure.core/map/fn
              LazySeq.java:   42  clojure.lang.LazySeq/sval
              LazySeq.java:   51  clojure.lang.LazySeq/seq
                   RT.java:  535  clojure.lang.RT/seq
                  core.clj:  137  clojure.core/seq
                  core.clj: 2809  clojure.core/filter/fn
              LazySeq.java:   42  clojure.lang.LazySeq/sval
              LazySeq.java:   51  clojure.lang.LazySeq/seq
          ChunkedCons.java:   59  clojure.lang.ChunkedCons/chunkedNext
          ChunkedCons.java:   43  clojure.lang.ChunkedCons/next
                   RT.java:  713  clojure.lang.RT/next
                  core.clj:   64  clojure.core/next
             protocols.clj:   63  clojure.core.protocols/naive-seq-reduce
             protocols.clj:   72  clojure.core.protocols/interface-or-naive-reduce
             protocols.clj:  169  clojure.core.protocols/fn
             protocols.clj:  124  clojure.core.protocols/fn
             protocols.clj:   19  clojure.core.protocols/fn/G
             protocols.clj:   31  clojure.core.protocols/seq-reduce
             protocols.clj:   75  clojure.core.protocols/fn
             protocols.clj:   75  clojure.core.protocols/fn
             protocols.clj:   13  clojure.core.protocols/fn/G
                  core.clj: 6828  clojure.core/reduce
                  core.clj: 6895  clojure.core/into
                  core.clj: 6887  clojure.core/into
              metadata.clj:  231  libpython-clj.metadata/datafy-module
              metadata.clj:  208  libpython-clj.metadata/datafy-module
               require.clj:  348  libpython-clj.require/eval36195/fn
              MultiFn.java:  229  clojure.lang.MultiFn/invoke
               require.clj:  360  libpython-clj.require/py-datafy
               require.clj:  359  libpython-clj.require/py-datafy
               require.clj:  398  libpython-clj.require/eval36238/fn
             protocols.clj:  182  clojure.core.protocols/fn/G
                datafy.clj:   23  clojure.datafy/datafy
                datafy.clj:   15  clojure.datafy/datafy
               require.clj:  134  libpython-clj.require/do-require-python
               require.clj:   92  libpython-clj.require/do-require-python
               require.clj:  276  libpython-clj.require/require-python
               require.clj:  177  libpython-clj.require/require-python
               require.clj:  274  libpython-clj.require/require-python
               require.clj:  177  libpython-clj.require/require-python

So it originates (in my case at least) from here:

https://github.com/clj-python/libpython-clj/blob/master/src/libpython_clj/python/object.clj#L907

Potentially I bound to pyerr_restore incorrectly as one of these objects is nil and perhaps that is OK while I have an explicit check to guarantee they aren't nill in the external C bindings.

from libpython-clj.

cnuernber avatar cnuernber commented on July 19, 2024

Got a bit further. In the metadata analysis of the sys module, we get:

ERROR!! #object[com.sun.jna.Pointer 0x30546999 native@0x7fb311e6bee0] #object[com.sun.jna.Pointer 0x2fd21b2 native@0x7fb3103fe7b0] nil
type #object[com.sun.jna.Pointer 0x30546999 native@0x7fb311e6bee0]
value #object[com.sun.jna.Pointer 0x2fd21b2 native@0x7fb3103fe7b0] dictionary changed size during iteration

from libpython-clj.

jjtolton avatar jjtolton commented on July 19, 2024

that's very interesting. I think it probably has something to do with the stack frames, like you were suggesting.

In [1]: d = {'a': 'b'}                                                                                                                                        

In [2]: for k,v in d.items(): 
   ...:     d['c'] = v 
   ...:                                                                                                                                                       
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-2-b538c53f99f1> in <module>
----> 1 for k,v in d.items():
      2     d['c'] = v
      3 

RuntimeError: dictionary changed size during iteration

I'm pretty sure the stack frames are kept in a dictionary.

from libpython-clj.

jjtolton avatar jjtolton commented on July 19, 2024

This might be it:

In [5]: sys._current_frames()                                                                                                                                 
Out[5]: 
{140197899065088: <frame at 0x14bd268>,
 140197530433280: <frame at 0x14bf4b8>,
 140197909653248: <frame at 0x14c6558>,
 140197480077056: <frame at 0x14c0008>,
 140197496862464: <frame at 0x147ca88>,
 140197889885952: <frame at 0x149f258>,
 140197513647872: <frame at 0x144b9c8>,
 140197929584384: <frame at 0x144c098>,
 140198014052160: <frame at 0x14a0d28>}

from libpython-clj.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.