Skip to content

Instantly share code, notes, and snippets.

@cowlicks
Last active October 2, 2019 05:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cowlicks/08f65799aeb1ed0d92988a017c5dd8f7 to your computer and use it in GitHub Desktop.
Save cowlicks/08f65799aeb1ed0d92988a017c5dd8f7 to your computer and use it in GitHub Desktop.
So you wanna run some asyncio code...
// Usage:
// dev with: dot -Tx11 this_file.dot
// output with: dot -Tpng this_file.dot > out_file.png
// change "png" above to desired output format
digraph asyncio {
"so you wanna run some asyncio code?" -> "do you want to run the code sequentially?";
"do you want to run the code sequentially?" -> "are you within an async block?"[ label="yes" ];
"are you within an async block?" -> "use await" [ label="yes" ];
"are you within an async block?" -> "is there already an event loop running in the current thread?" [ label="no" ];
"is there already an event loop running in the current thread?" -> "use asyncio.run" [ label="no" ];
"is there already an event loop running in the current thread?" -> "that sucks, you gotta run it in another process and wait" [ label="yes" ];
"do you want to run the code sequentially?" -> "is there an event loop running in the current process?"[ label="no" ];
"is there an event loop running in the current process?" -> "use create task" [ label="yes" ];
"is there an event loop running in the current process?" -> "run it in another thread" [ label="no" ];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment