HyukjinKwon commented on a change in pull request #26239: 
[SPARK-29582][PYSPARK] Support `TaskContext.get()` in a barrier task from 
Python side
URL: https://github.com/apache/spark/pull/26239#discussion_r340936674
 
 

 ##########
 File path: python/pyspark/tests/test_taskcontext.py
 ##########
 @@ -181,6 +227,40 @@ def context_barrier(x):
         for pid in pids:
             self.assertTrue(pid in worker_pids)
 
+    def test_task_context_correct_with_python_worker_reuse(self):
+        """Verify the task context correct when reused python worker"""
+        # start a normal job first to start all workers and get all worker pids
+        worker_pids = self.sc.parallelize(xrange(2), 2).map(lambda x: 
os.getpid()).collect()
+        # the worker will reuse in this barrier job
+        rdd = self.sc.parallelize(xrange(10), 2)
+
+        def context(iterator):
+            tp = TaskContext.get().partitionId()
+            try:
+                bp = BarrierTaskContext.get().partitionId()
+            except Exception:
+                bp = -1
+
+            yield (tp, bp, os.getpid())
+
+        def verify(result, task_context_target, barrier_context_target):
+            tps = list(map(lambda x: x[0], result))
+            bps = list(map(lambda x: x[1], result))
+            pids = list(map(lambda x: x[2], result))
 
 Review comment:
   BTW, iterable unpacking works with list(tuple) too

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to