Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HDFS access within multiprocessing.Process can lead to deadlocks #311

Closed
simleo opened this issue May 22, 2018 · 2 comments
Closed

HDFS access within multiprocessing.Process can lead to deadlocks #311

simleo opened this issue May 22, 2018 · 2 comments

Comments

@simleo
Copy link
Member

simleo commented May 22, 2018

The following code can hang indefinitely:

from multiprocessing import Process
from pydoop.hdfs.core import init
hdfs = init()

def connect():
    fs = None
    try:
        fs = hdfs.CoreHdfsFs("default", 0)
    finally:
        if fs:
            fs.close()

connect()
p = Process(target=connect)
p.start()
p.join()

The call to connect in the main program completes successfully, but the one spawned as a Process hangs indefinitely in:

hdfsBuilderConnect
  ==> invokeMethod(... "getDefaultUri" ...)
    ==> (*env)->CallStaticObjectMethodV

Note that spawning multiple processes does NOT lead to problems if HDFS is not accessed in the main program, i.e., the following is OK:

procs = [Process(target=connect) for _ in range(3)]
for p in procs:
    p.start()
for p in procs:
    p.join()

The issue also disappears if multiprocessing is replaced with threading:

from threading import Thread
[...]
connect()
t = Thread(target=connect)
t.start()
t.join()
@ben-davidson-6
Copy link

changing the way you start the process fixes this problem. See here dask/hdfs3#100. In short if you add

import multiprocessing as mp

...

if __name__ == '__main__':
    mp.set_start_method('forkserver')
    ...

it works.

@simleo
Copy link
Member Author

simleo commented Jun 30, 2021

Thanks for the tip @ben-davidson-6! It's been a while, but I could not even reproduce the issue (it's working for me with all start methods). Anyway, closing this since there's a workaround.

@simleo simleo closed this as completed Jun 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants