modin icon indicating copy to clipboard operation
modin copied to clipboard

RuntimeError for multiprocessing

Open junxu-ai opened this issue 7 years ago • 26 comments

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows 10 + CUDA
  • Modin installed from (source or binary): pip install modin[dask]
  • Modin version: 0.6.2
  • Python version:3.6
  • Exact command to reproduce:

import modin.pandas as pd df=pd.read_csv(r"c:\temp\huge_size_csv.csv")

Describe the problem

RuntimeError: Attempt to start a new process before the current process has finished its bootstrapping phase. This probably means that you are on Windows and you have forgotten to use the proper idiom in the main module: if name == 'main': freeze_support() ... The "freeze_support()" line can be omitted if the program is not going to be frozen to produce a Windows executable.

Source code / logs

import modin.pandas as pd df=pd.read_csv(r"c:\temp\huge_size_csv.csv")

Note that there is no issue if i run the code in the python console one by one. However, in this case, the time cost of modin is longer than the normal pandas.

junxu-ai avatar Oct 25 '19 06:10 junxu-ai

Hi @junxuwdc, thanks for posting!

For the dask backend, I/O support is not completely finished yet. #754 is a first step toward that and the I/O support for dask will be ready for the next release.

For the freeze_support issue, I will take a look at that as well. Thanks for reporting!

Thanks again for posting!

devin-petersohn avatar Oct 25 '19 16:10 devin-petersohn

same problem here.

janwendt avatar Nov 04 '19 13:11 janwendt

Thanks @junxuwdc and @janwendt, this is related to https://github.com/dask/distributed/issues/2520.

I can put the fix in today, thanks!

devin-petersohn avatar Nov 04 '19 17:11 devin-petersohn

For a quick fix, you can just add the following to your script:

if __name__ == "__main__":
    import modin.pandas as pd
    df=pd.read_csv(r"c:\temp\huge_size_csv.csv")
    ...

I am not sure of the right way to handle this in Modin at the moment after digging into it a bit.

Since this isn't related to the read_csv Not Implemented issue I'm going to remove the tags related to that.

devin-petersohn avatar Nov 04 '19 18:11 devin-petersohn

+1 for the issue.

Windows 10. py3.7 :(

ee- avatar Mar 07 '20 21:03 ee-

@ee- This is not fixable. It is a property of Dask Client when running on Windows, and cannot be bypassed. Unfortunately the only fix is the one listed above.

devin-petersohn avatar Mar 07 '20 22:03 devin-petersohn

@ee- This is not fixable. It is a property of Dask Client when running on Windows, and cannot be bypassed. Unfortunately the only fix is the one listed above.

Well this project is significantly very new and in early stage, yet I would appreciate if this could be fixed? Even with the work around you provided, i can not import the library in other modules where pandas is being used as they are not in main namespace.

chetansurwade avatar Apr 18 '20 15:04 chetansurwade

I am not sure that this problem is Windows specific. I've seen Dask output tons of exceptions on Linux when I forgot to add if __name__ == "__main__": to my program. So it is definitely Dask specific, but I think it is cross-patform.

gshimansky avatar Apr 18 '20 16:04 gshimansky

I am not sure that this problem is Windows specific. I've seen Dask output tons of exceptions on Linux when I forgot to add if __name__ == "__main__": to my program. So it is definitely Dask specific, but I think it is cross-patform.

Okay, Any progress with Ray backend on Windows? Ray is also a Berkeley project, so the cross platform integration of the two should be the priority, at least that's what i think.

chetansurwade avatar Apr 18 '20 16:04 chetansurwade

Lets say i import this in main file, Is there a way I could use this import in other files as well like other modules, if yes then how?

chetansurwade avatar May 14 '20 14:05 chetansurwade

Really liked the project but, can not use it. Any help here appreciated.

chetansurwade avatar May 14 '20 14:05 chetansurwade

@chetansurwade It may help to initialize a Dask client before you import modin:

from distributed import Client
client = Client()
import modin.pandas as pd

You should only initialize the client once in the project. Modin can connect to it after it is created.

devin-petersohn avatar May 14 '20 15:05 devin-petersohn

Tried with it. Didn't work. I have multiple modules using pandas and as suggested in the documentation i replaced the import statement, I've also tried the approach you mentioned, initializing dask client in main file - didn't work, in init file didn't work after name == main in main file- didn't work.

chetansurwade avatar May 14 '20 15:05 chetansurwade

I think this stems from issues with using Dask/Multiprocessing in a script that we cannot really fix, because it fundamental to those implementations.

Ray has made some progress on Windows: ray-project/ray#631

devin-petersohn avatar May 14 '20 16:05 devin-petersohn

So basically either I'll have to wait for ray on windows or dig into the issue myself :-(

chetansurwade avatar May 14 '20 16:05 chetansurwade

I am saying digging into the issue yourself will probably not yield much. I have spent many hours trying to work around and fix this only to conclude that it cannot be worked around. There are some things, positive and negative, that Modin inherits from dependencies. This is one of the unfortunate cases.

I don't have the issue with Ray, which is why I mention it. It may already be possible to use Ray with Windows, maybe with some bugs because it is new.

I would absolutely fix this if I could, it is an important usecase.

devin-petersohn avatar May 14 '20 16:05 devin-petersohn

I'll wait for a stable release in that case and use just pandas till then. Thanks for the information anyway.

chetansurwade avatar May 14 '20 16:05 chetansurwade

This issue has been mentioned on Modin Discuss. There might be relevant details there:

https://discuss.modin.org/t/dask-error-when-running-modin-pandas/112/2

modin-bot avatar May 15 '20 15:05 modin-bot

@devin-petersohn same issue, I'm using ubuntu 18.04. It's working fine with ray. but when I added env to dask. It keeps throwing this error even for the small code.

tried sample code: ` from distributed import Client client = Client(n_workers=6) import modin.pandas as pd

if name == "main":

path= "path/to/file"
modin_df = pd.read_parquet(path)
modin_df.to_parquet("path2/test.parquet")
print(f'Modin DF len = {len(modin_df)}')`

Error trace:

`Task exception was never retrieved future: <Task finished coro=<_wrap_awaitable() done, defined at /usr/lib/python3.6/asyncio/tasks.py:530> exception=RuntimeError('\n An attempt has been made to start a new process before the\n current process has finished its bootstrapping phase.\n\n This probably means that you are not using fork to start your\n child processes and you have forgotten to use the proper idiom\n in the main module:\n\n if name == 'main':\n freeze_support()\n ...\n\n The "freeze_support()" line can be omitted if the program\n is not going to be frozen to produce an executable.',)> Traceback (most recent call last): File "/usr/lib/python3.6/asyncio/tasks.py", line 537, in _wrap_awaitable return (yield from awaitable.await()) File "/home/srds/virtual_env/airflow_venv/lib/python3.6/site-packages/distributed/nanny.py", line 291, in start response = await self.instantiate() File "/home/srds/virtual_env/airflow_venv/lib/python3.6/site-packages/distributed/nanny.py", line 374, in instantiate result = await self.process.start() File "/home/srds/virtual_env/airflow_venv/lib/python3.6/site-packages/distributed/nanny.py", line 567, in start await self.process.start() File "/home/srds/virtual_env/airflow_venv/lib/python3.6/site-packages/distributed/process.py", line 34, in _call_and_set_future res = func(*args, **kwargs) File "/home/srds/virtual_env/airflow_venv/lib/python3.6/site-packages/distributed/process.py", line 202, in _start process.start() File "/usr/lib/python3.6/multiprocessing/process.py", line 105, in start self._popen = self._Popen(self) File "/usr/lib/python3.6/multiprocessing/context.py", line 284, in _Popen return Popen(process_obj) File "/usr/lib/python3.6/multiprocessing/popen_spawn_posix.py", line 32, in init super().init(process_obj) File "/usr/lib/python3.6/multiprocessing/popen_fork.py", line 19, in init self._launch(process_obj) File "/usr/lib/python3.6/multiprocessing/popen_spawn_posix.py", line 42, in _launch prep_data = spawn.get_preparation_data(process_obj._name) File "/usr/lib/python3.6/multiprocessing/spawn.py", line 143, in get_preparation_data _check_not_importing_main() File "/usr/lib/python3.6/multiprocessing/spawn.py", line 136, in _check_not_importing_main is not going to be frozen to produce an executable.''') RuntimeError: An attempt has been made to start a new process before the current process has finished its bootstrapping phase.

    This probably means that you are not using fork to start your
    child processes and you have forgotten to use the proper idiom
    in the main module:

        if __name__ ==" __main__":
            freeze_support()`

itsmesrds avatar May 21 '20 04:05 itsmesrds

@devin-petersohn same issue, I'm using ubuntu 18.04. It's working fine with ray. but when I added env to dask. It keeps throwing this error even for the small code.

tried sample code: ` from distributed import Client client = Client(n_workers=6) import modin.pandas as pd

if name == "main":

path= "path/to/file"
modin_df = pd.read_parquet(path)
modin_df.to_parquet("path2/test.parquet")
print(f'Modin DF len = {len(modin_df)}')`

Error trace:

`Task exception was never retrieved future: <Task finished coro=<_wrap_awaitable() done, defined at /usr/lib/python3.6/asyncio/tasks.py:530> exception=RuntimeError('\n An attempt has been made to start a new process before the\n current process has finished its bootstrapping phase.\n\n This probably means that you are not using fork to start your\n child processes and you have forgotten to use the proper idiom\n in the main module:\n\n if name == 'main':\n freeze_support()\n ...\n\n The "freeze_support()" line can be omitted if the program\n is not going to be frozen to produce an executable.',)> Traceback (most recent call last): File "/usr/lib/python3.6/asyncio/tasks.py", line 537, in _wrap_awaitable return (yield from awaitable.await()) File "/home/srds/virtual_env/airflow_venv/lib/python3.6/site-packages/distributed/nanny.py", line 291, in start response = await self.instantiate() File "/home/srds/virtual_env/airflow_venv/lib/python3.6/site-packages/distributed/nanny.py", line 374, in instantiate result = await self.process.start() File "/home/srds/virtual_env/airflow_venv/lib/python3.6/site-packages/distributed/nanny.py", line 567, in start await self.process.start() File "/home/srds/virtual_env/airflow_venv/lib/python3.6/site-packages/distributed/process.py", line 34, in _call_and_set_future res = func(*args, **kwargs) File "/home/srds/virtual_env/airflow_venv/lib/python3.6/site-packages/distributed/process.py", line 202, in _start process.start() File "/usr/lib/python3.6/multiprocessing/process.py", line 105, in start self._popen = self._Popen(self) File "/usr/lib/python3.6/multiprocessing/context.py", line 284, in _Popen return Popen(process_obj) File "/usr/lib/python3.6/multiprocessing/popen_spawn_posix.py", line 32, in init super().init(process_obj) File "/usr/lib/python3.6/multiprocessing/popen_fork.py", line 19, in init self._launch(process_obj) File "/usr/lib/python3.6/multiprocessing/popen_spawn_posix.py", line 42, in _launch prep_data = spawn.get_preparation_data(process_obj._name) File "/usr/lib/python3.6/multiprocessing/spawn.py", line 143, in get_preparation_data _check_not_importing_main() File "/usr/lib/python3.6/multiprocessing/spawn.py", line 136, in _check_not_importing_main is not going to be frozen to produce an executable.''') RuntimeError: An attempt has been made to start a new process before the current process has finished its bootstrapping phase.

    This probably means that you are not using fork to start your
    child processes and you have forgotten to use the proper idiom
    in the main module:

        if __name__ ==" __main__":
            freeze_support()`

That's a dask related issue. Running dask in modular package environment or scripts is a mess.

chetansurwade avatar May 21 '20 14:05 chetansurwade