-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Iterator support (TypeError: argument of type 'dict' is not iterable) #13
Comments
In CPython 2.7 dictobject.c there is a section starting with the comment |
I had a look at As this is a side project for me, I cannot promise that I will make any progress with this but I will come back to it when I have some spare time! |
Yes, that is exactly right. You can use |
Regarding ImageJ:
JyNI requires Jython, which is unfortunately not that lightweight in terms of shipping. Or does Fiji ship Jython anyway? |
Do you think that this is likely to happen? If so, I would prefer to wait. Thanks for pointing to JyNI.c:1001. |
Yes, Fiji does ship Jython, so that dependency would not be an issue. Shipping the CPython extensions (numpy, etc.) will be more of a headache. Maybe we will be able to use conda for that. Currently, as you might have seen in the ImageJ forum thread you referenced, there is imglyb which uses PyJNIus to start a JVM from a running python process for shared memory between python and Java. We can use this to launch ImageJ/Fiji from that Python process but I definitely see benefits in having the JVM as the main process, e.g. awt in python on OSX, so for us it is definitely worth looking into JyNI. That being said, the code changes required for imglyb to work with JyNI are very minor, so I think it is definitely worth to pursue both the Jython and CPython solutions at the same time. |
That depends on us. I can push such a change to Jython if it's reasonable. It is unlikely that someone else will take hands on this dictionary stuff. The question is if we see a way to unify iterator types of |
…g AbstractDict and to better match CPython's variant. Simplifies fixing of Stewori/JyNI#13.
With https://hg.python.org/jython/rev/ddb684156587 I refined things in Jython a bit.
|
At some point you said that some iterators were implemented to some degree, the sequence iterator in particular. There are a number of iterators in different files, the sequence iterator is the only one with code that seems to manage GC in the JyNI way, so the others may have memory leaks, but I'm not sure.
To implement more, and deal with #32, I think I need to understand GC better. I think the focus of my confusion is around the core question: where do and don't we need to increment reference counts. What I (think I) know:I think C variables created without malloc stick around until they are out of scope. But there is something to do with PyObjects where malloc is used so free would be needed, but I don't know the details. PyObjects also seem to store a refcnt so I think GC deals with them. When GC occurs it maps the tree of references and uses that to work out what it can free. I don't think I need to know the details of exactly how it does that (although I do know some from talks and papers on jyni.org) so long as I know/trust that things with references pointing to them won't be GC'd. What I don't know (about PySeqIter and ref counting):I'm not really sure what a
|
These are very good questions and I'll try to answer them. However maybe not all right now. A
Regarding GC handling, in JyNI there operates kind of a native part of GC that cares about modeling the native reference graph on Java side with JyGCHeads. That's in gcmodule.c. This only tangents native objects that hold native references to other native objects. E.g. So much for now. We can iterate on details. |
…g AbstractDict and to better match CPython's variant. Simplifies fixing of Stewori/JyNI#13.
…g AbstractDict and to better match CPython's variant. Simplifies fixing of Stewori/JyNI#13.
This is exciting and looks very promising! I was able to download the binaries and run them on my machine (Arch Linux). I was able to import
numpy
and tested basic functionality, e.g. this works:I was not able to generate a random int, though:
This is a migration to a separate issue from #2 . Following up on @Stewori's comment I looked for
PyDict_Iter
but my search was not successful. My best guess would be to get the iterator from the list returned byPyDict_Items
when requested. Maybe that happens already and it will be resolved automatically onceListIter
is supported.I am not very familiar with the Python C API but I would definitely have a look into it. If you could point me to where the iterator methods for the python objects are defined, that would make it a lot easier for me!
You can probably add
Arch Linux
to the systems JyNI has been tested on. I did not build it myself, though.If you are interested in why we would like to use JyNI: I created a compatibility layer between numpy and imglib2 based on pyjnius: imglib2-imglyb. This library is the core for modern ImageJ and with that compatibility layer we try to get the best of both worlds. The python code of
imglyb
needs only slight modificatoins to work with JyNI, and shipping JyNI with Fiji would probably be much easier than shipping a whole CPython distribution, so we are very interested in what happens with JyNI.The text was updated successfully, but these errors were encountered: