{"action":"created","issue":{"url":"https://api.github.com/repos/grosser/parallel/issues/174","repository_url":"https://api.github.com/repos/grosser/parallel","labels_url":"https://api.github.com/repos/grosser/parallel/issues/174/labels{/name}","comments_url":"https://api.github.com/repos/grosser/parallel/issues/174/comments","events_url":"https://api.github.com/repos/grosser/parallel/issues/174/events","html_url":"https://github.com/grosser/parallel/issues/174","id":153537583,"number":174,"title":"Does not work with enumerators","user":{"login":"cjbottaro","id":10292,"avatar_url":"https://avatars.githubusercontent.com/u/10292?v=3","gravatar_id":"","url":"https://api.github.com/users/cjbottaro","html_url":"https://github.com/cjbottaro","followers_url":"https://api.github.com/users/cjbottaro/followers","following_url":"https://api.github.com/users/cjbottaro/following{/other_user}","gists_url":"https://api.github.com/users/cjbottaro/gists{/gist_id}","starred_url":"https://api.github.com/users/cjbottaro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cjbottaro/subscriptions","organizations_url":"https://api.github.com/users/cjbottaro/orgs","repos_url":"https://api.github.com/users/cjbottaro/repos","events_url":"https://api.github.com/users/cjbottaro/events{/privacy}","received_events_url":"https://api.github.com/users/cjbottaro/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-05-06T21:02:28Z","updated_at":"2016-05-06T21:19:28Z","closed_at":null,"body":"Hello,\r\n\r\nThis code doesn't work:\r\n\r\n```\r\nenumerator = File.open(\"/usr/share/dict/words\").each_line\r\n\r\nproducer = lambda do\r\n  begin\r\n    enumerator.next\r\n  rescue StopIteration\r\n    Parallel::Stop\r\n  end\r\nend\r\n\r\nParallel.each producer, in_processes: 4 do |i|\r\n  print \"#{Process.pid} #{i}\\n\"\r\nend\r\n```\r\n\r\nIt results in `fiber called across threads (FiberError)`.\r\n\r\nI poked around in the code; why are there 4 threads \"feeding\" the processes?  Why not just have the main thread pluck items from the lambda to give to an available worker?\r\n\r\nThanks!"},"comment":{"url":"https://api.github.com/repos/grosser/parallel/issues/comments/217561116","html_url":"https://github.com/grosser/parallel/issues/174#issuecomment-217561116","issue_url":"https://api.github.com/repos/grosser/parallel/issues/174","id":217561116,"user":{"login":"grosser","id":11367,"avatar_url":"https://avatars.githubusercontent.com/u/11367?v=3","gravatar_id":"","url":"https://api.github.com/users/grosser","html_url":"https://github.com/grosser","followers_url":"https://api.github.com/users/grosser/followers","following_url":"https://api.github.com/users/grosser/following{/other_user}","gists_url":"https://api.github.com/users/grosser/gists{/gist_id}","starred_url":"https://api.github.com/users/grosser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grosser/subscriptions","organizations_url":"https://api.github.com/users/grosser/orgs","repos_url":"https://api.github.com/users/grosser/repos","events_url":"https://api.github.com/users/grosser/events{/privacy}","received_events_url":"https://api.github.com/users/grosser/received_events","type":"User","site_admin":false},"created_at":"2016-05-06T21:19:28Z","updated_at":"2016-05-06T21:19:28Z","body":"keeping the lambda on the main thread sounds like a good idea ...\ninternally it does a @mutex.synchronize around the lambda call ... but not\nsure how to make it stay on the main thread ...\n\n\nOn Fri, May 6, 2016 at 2:02 PM, Christopher J. Bottaro <\nnotifications@github.com> wrote:\n\n> Hello,\n>\n> This code doesn't work:\n>\n> enumerator = File.open(\"/usr/share/dict/words\").each_line\n>\n> producer = lambda do\n>   begin\n>     enumerator.next\n>   rescue StopIteration\n>     Parallel::Stop\n>   end\n> end\n>\n> Parallel.each producer, in_processes: 4 do |i|\n>   print \"#{Process.pid} #{i}\\n\"\n> end\n>\n> It results in fiber called across threads (FiberError).\n>\n> I poked around in the code; why are there 4 threads \"feeding\" the\n> processes? Why not just have the main thread pluck items from the lambda to\n> give to an available worker?\n>\n> Thanks!\n>\n> —\n> You are receiving this because you are subscribed to this thread.\n> Reply to this email directly or view it on GitHub\n> <https://github.com/grosser/parallel/issues/174>\n>\n"}}