Copied from another answer:
It was perfectly fine if execute the same piece of code through PyCharm in non-debug (Run) mode. Disabled the above code in debug mode, issue resolved.
Try to run in non-debug mode.