# How can I tell if I'm on a worker or the driver? Is there something like \`multiprocessing.parent\_process()\`?

**URL:** <https://discuss.ray.io/t/how-can-i-tell-if-im-on-a-worker-or-the-driver-is-there-something-like-multiprocessing-parent-process/6054>\
**Category:** Ray Core\
**Created:** [May 6, 2022, 10:27pm UTC](https://discuss.ray.io/t/how-can-i-tell-if-im-on-a-worker-or-the-driver-is-there-something-like-multiprocessing-parent-process/6054 "2022-05-06T22:27:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![wmayner](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/wmayner/32/2308_2.png) [@wmayner](https://discuss.ray.io/u/wmayner)\
**Post date:** [May 6, 2022, 10:27pm UTC](https://discuss.ray.io/t/how-can-i-tell-if-im-on-a-worker-or-the-driver-is-there-something-like-multiprocessing-parent-process/6054/1 "2022-05-06T22:27:21Z")

</div>

**How severe does this issue affect your experience of using Ray?**

- Medium: It contributes to significant difficulty to complete my task, but I can work around it.

Is there a way of telling, from within a Python module, whether I’m on a ray worker or the driver? For example, something like the builtin `multiprocessing.parent_process()`.

---

<div class="post-metadata">

**Author:** ![sangcho](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/sangcho/32/425_2.png) [@sangcho](https://discuss.ray.io/u/sangcho)\
**Post date:** [May 9, 2022, 9:32pm UTC](https://discuss.ray.io/t/how-can-i-tell-if-im-on-a-worker-or-the-driver-is-there-something-like-multiprocessing-parent-process/6054/2 "2022-05-09T21:32:05Z")

</div>

Can you tell me the use case a little bit? (I imagine that normally it’s straightforward to figure out what’s driver?) I don’t think there’s an official API, but there is a way to do this by combining some existing APIs.

---

<div class="post-metadata">

**Author:** ![ericl](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/ericl/32/133_2.png) [@ericl](https://discuss.ray.io/u/ericl)\
**Post date:** [May 10, 2022, 3:50am UTC](https://discuss.ray.io/t/how-can-i-tell-if-im-on-a-worker-or-the-driver-is-there-something-like-multiprocessing-parent-process/6054/3 "2022-05-10T03:50:59Z")

</div>

One way to do this is to get `ray.get_runtime_context().task_id`. It will raise an error if the current process is not a task worker.

More about runtime\_context here: [ray.runtime\_context — Ray 1.12.0](https://docs.ray.io/en/latest/_modules/ray/runtime_context.html)

---

<div class="post-metadata">

**Author:** ![wmayner](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/wmayner/32/2308_2.png) [@wmayner](https://discuss.ray.io/u/wmayner)\
**Post date:** [May 11, 2022, 7:27pm UTC](https://discuss.ray.io/t/how-can-i-tell-if-im-on-a-worker-or-the-driver-is-there-something-like-multiprocessing-parent-process/6054/4 "2022-05-11T19:27:38Z")

</div>

Thanks @ericl , I didn’t know about that—very useful. I ended up setting a custom environment variable using the `runtime_env` argument to `ray.remote`, but your solution is more elegant.

@sangcho, the use case is the following: I have a configuration object that the user can modify at will, and I want any changes to be visible to workers. My approach is to write the configuration to disk anytime it’s changed, and then load that file on the workers when my library is imported (I’m not worried about potential race conditions here, but of course this is not ideal). But the catch is, I also want to load the user’s configuration on import—so I need to load from different locations depending on whether I’m on the driver or not.

If you know of a better pattern for this kind of global-variable sharing, I’m all ears!
