# Python generators equivalent?

**URL:** <https://forum.elixirforum.com/t/python-generators-equivalent/2806>\
**Category:** Questions\
**Tags:** generators\
**Created:** [December 9, 2016, 10:34am UTC](https://forum.elixirforum.com/t/python-generators-equivalent/2806 "2016-12-09T10:34:08Z")\
**Posts on this page:** 1\
**Showing post:** 12

<div class="post-metadata">

**Author:** ![peerreynders](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/peerreynders/32/5826_2.png) [@peerreynders](https://forum.elixirforum.com/u/peerreynders)\
**Post date:** [April 27, 2017, 8:28pm UTC](https://forum.elixirforum.com/t/python-generators-equivalent/2806/12 "2017-04-27T20:28:44Z")

</div>

> [@Qqwy](#):
>
> The third one, ‘cheating’ using message-passing, is often too much overhead for what you want to use the generator for. Exceptions of course do exist: A GenServer that returns guaranteed-unique identifiers, for instance.

I don’t think it’s cheating. It’s taking advantage of the environment’s capabilities. Due to their threaded nature, languages like Python and [JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator) have to have dedicated language constructs for generators.

[Joe Armstrong demonstrates building a Future with concurrency features](https://youtu.be/0jsdXFUvQKE?t=272), so if you _need_ a generator - go ahead, use a process (even a GenServer) to build one. I still need to completely digest “[To spawn, or not to spawn?](http://theerlangelist.com/article/spawn_or_not)” but I’m not advocating going on a spawn-fest; just sometimes it is good to leave the “sequential mindset” behind.

---

_[View the full topic](https://forum.elixirforum.com/t/python-generators-equivalent/2806)._
