# Processing.py issue with user-created generator (yield)

**URL:** <https://discourse.processing.org/t/processing-py-issue-with-user-created-generator-yield/14011>\
**Category:** Processing.py\
**Created:** [September 16, 2019, 9:31am UTC](https://discourse.processing.org/t/processing-py-issue-with-user-created-generator-yield/14011 "2019-09-16T09:31:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![zlohner](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/zlohner/32/6450_2.png) [@zlohner](https://discourse.processing.org/u/zlohner)\
**Post date:** [September 16, 2019, 9:31am UTC](https://discourse.processing.org/t/processing-py-issue-with-user-created-generator-yield/14011/1 "2019-09-16T09:31:59Z")

</div>

New to Processing but experienced in programming, especially python. I decided implementing Conway’s Game of Life would be a good project to get a feel for how to use Processing.py

My code involved a function that returned a generator for the neighbors of a given cell, yielding the coordinates for each neighboring cell as a tuple. This is quite common in python, and as far as I know has no performance issues in native python as compared with compiling a list of the neighbors and returning it.

Upon running the sketch, however, I was experiencing periodic pauses in the animation loop. I spent quite a bit of time trying to find the performance hiccup, and eventually tried changing the generator code to just construct and return a list. To my surprise, this immediately fixed the issue.

Is there something inherently inefficient about using generator functions in Processing.py (i.e. functions that yield instead of return)? Has anyone else run into a similar issue? I’m fine avoiding using yield but I would like to understand why it causes a problem.

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [September 16, 2019, 10:26am UTC](https://discourse.processing.org/t/processing-py-issue-with-user-created-generator-yield/14011/2 "2019-09-16T10:26:33Z")

</div>

Ignore me; I don’t know what I am taking about.

---

<div class="post-metadata">

**Author:** ![villares](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/villares/32/3166_2.png) [@villares](https://discourse.processing.org/u/villares)\
**Post date:** [September 16, 2019, 3:40pm UTC](https://discourse.processing.org/t/processing-py-issue-with-user-created-generator-yield/14011/3 "2019-09-16T15:40:11Z")

</div>

Hi!

Processing Python Mode is based on Jython, a Python 2.7 interpreter that uses the JVM.  
I really don’t know why the user-created generator has such a performance penalty ☹

If you can think of a minimal example to test this issue it might be nice to open an issue at [https://github.com/jdf/Processing.py-Bugs/](https://github.com/jdf/Processing.py-Bugs/)

For your amusement, yet another Conway’s Game of Life naive implementation:

> <https://github.com/villares/py.processing-play/blob/master/cellular_automata/yet_another_CGoL/yet_another_CGoL.pyde>

---

<div class="post-metadata">

**Author:** ![zlohner](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/zlohner/32/6450_2.png) [@zlohner](https://discourse.processing.org/u/zlohner)\
**Post date:** [September 17, 2019, 2:32am UTC](https://discourse.processing.org/t/processing-py-issue-with-user-created-generator-yield/14011/4 "2019-09-17T02:32:45Z")

</div>

Thanks for the reply, I will try to find a minimal example and open an issue.
