{"action":"created","issue":{"url":"https://api.github.com/repos/jonathanslenders/python-prompt-toolkit/issues/507","repository_url":"https://api.github.com/repos/jonathanslenders/python-prompt-toolkit","labels_url":"https://api.github.com/repos/jonathanslenders/python-prompt-toolkit/issues/507/labels{/name}","comments_url":"https://api.github.com/repos/jonathanslenders/python-prompt-toolkit/issues/507/comments","events_url":"https://api.github.com/repos/jonathanslenders/python-prompt-toolkit/issues/507/events","html_url":"https://github.com/jonathanslenders/python-prompt-toolkit/issues/507","id":230232492,"number":507,"title":"`patch_stdout` lines printed out of order","user":{"login":"johshoff","id":353935,"avatar_url":"https://avatars2.githubusercontent.com/u/353935?v=3","gravatar_id":"","url":"https://api.github.com/users/johshoff","html_url":"https://github.com/johshoff","followers_url":"https://api.github.com/users/johshoff/followers","following_url":"https://api.github.com/users/johshoff/following{/other_user}","gists_url":"https://api.github.com/users/johshoff/gists{/gist_id}","starred_url":"https://api.github.com/users/johshoff/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/johshoff/subscriptions","organizations_url":"https://api.github.com/users/johshoff/orgs","repos_url":"https://api.github.com/users/johshoff/repos","events_url":"https://api.github.com/users/johshoff/events{/privacy}","received_events_url":"https://api.github.com/users/johshoff/received_events","type":"User","site_admin":false},"labels":[{"id":76984990,"url":"https://api.github.com/repos/jonathanslenders/python-prompt-toolkit/labels/bug","name":"bug","color":"fc2929","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2017-05-21T16:42:58Z","updated_at":"2017-06-16T21:57:30Z","closed_at":null,"body":"Lines printed from an `inputhook` might be printed out of order when doing `patch_stdout`.\r\n\r\nExample to illustrate:\r\n\r\n```python\r\nfrom __future__ import unicode_literals\r\nfrom prompt_toolkit.shortcuts import prompt, create_eventloop\r\nfrom time import sleep\r\n\r\nx = 0\r\ndef inputhook(context):\r\n    global x\r\n\r\n    print('%d before sleep' % x)\r\n    x = x + 1\r\n    sleep(1)\r\n    print('%d after sleep' % x)\r\n    x = x + 1\r\n\r\nprompt('> ',\r\n       eventloop=create_eventloop(inputhook=inputhook),\r\n       patch_stdout=True)\r\n```\r\n\r\nExample output (the order will be different between runs):\r\n\r\n```\r\n0 before sleep\r\n1 after sleep\r\n2 before sleep\r\n3 after sleep\r\n5 after sleep\r\n4 before sleep\r\n```\r\n\r\nExpected numbers to be 0, 1, 2, 3, ***4, 5***, but instead they are 0, 1, 2, 3, ***5, 4***.\r\n\r\nRunning MacOS 10.11.6 and iterm2 3.0.15.\r\n\r\nObservations so far:\r\n\r\n• the behavior is the same on python 2.7 and python 3.5\r\n• the behavior is (unsurprisingly) the same even if use `sys.stdout.write` and `sys.stdout.flush()` instead of `print`, however, if I `write` without a newline, lines are in order."},"comment":{"url":"https://api.github.com/repos/jonathanslenders/python-prompt-toolkit/issues/comments/309143809","html_url":"https://github.com/jonathanslenders/python-prompt-toolkit/issues/507#issuecomment-309143809","issue_url":"https://api.github.com/repos/jonathanslenders/python-prompt-toolkit/issues/507","id":309143809,"user":{"login":"jonathanslenders","id":216638,"avatar_url":"https://avatars0.githubusercontent.com/u/216638?v=3","gravatar_id":"","url":"https://api.github.com/users/jonathanslenders","html_url":"https://github.com/jonathanslenders","followers_url":"https://api.github.com/users/jonathanslenders/followers","following_url":"https://api.github.com/users/jonathanslenders/following{/other_user}","gists_url":"https://api.github.com/users/jonathanslenders/gists{/gist_id}","starred_url":"https://api.github.com/users/jonathanslenders/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jonathanslenders/subscriptions","organizations_url":"https://api.github.com/users/jonathanslenders/orgs","repos_url":"https://api.github.com/users/jonathanslenders/repos","events_url":"https://api.github.com/users/jonathanslenders/events{/privacy}","received_events_url":"https://api.github.com/users/jonathanslenders/received_events","type":"User","site_admin":false},"created_at":"2017-06-16T21:57:30Z","updated_at":"2017-06-16T21:57:30Z","body":"Hi @atherra,\r\n\r\nThanks, that's correct. I believe it's fine to simply remove the ``shuffle`` calls.\r\nCould you test the master branch, and see whether this fixes it?\r\n\r\n"}}
{"actor":{"display_login":"jonathanslenders"}}