summaryrefslogtreecommitdiff
path: root/concurrent_append.py
diff options
context:
space:
mode:
Diffstat (limited to 'concurrent_append.py')
-rw-r--r--concurrent_append.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/concurrent_append.py b/concurrent_append.py
new file mode 100644
index 0000000..8572e94
--- /dev/null
+++ b/concurrent_append.py
@@ -0,0 +1,24 @@
+#
+# Shamelessly stolen from the following StackOverflow response:
+# https://stackoverflow.com/a/56792928/6150271
+#
+
+import time
+from concurrent.futures import ProcessPoolExecutor
+
+id_array = [*range(10)]
+
+def myfunc(id):
+ time.sleep(5)
+ if id % 2 == 0:
+ return id, id
+ else:
+ return id, id ** 2
+
+
+result = []
+with ProcessPoolExecutor() as executor:
+ for r in executor.map(myfunc, id_array):
+ result.append(r)
+
+print(result)