Skip to content

Commit

Permalink
only allow multiprocess on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
datawhores committed Aug 30, 2024
1 parent a959ca8 commit 8e394e8
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 20 deletions.
1 change: 0 additions & 1 deletion ofscraper/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


def main():
system.set_mulitproc_start_type()
if system.get_parent():
load.main()

Expand Down
5 changes: 2 additions & 3 deletions ofscraper/actions/actions/download/batch/downloadbatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,9 @@ async def process_dicts(username, model_id, filtered_medialist, posts):
count=1,
)
log_threads.append(thread)

processes = [
aioprocessing.AioProcess(
target=process_dict_starter,
aioprocessing.mp.get_context(system.get_mulitproc_start_type()).Process(
target=process_dict_starter,
args=(
username,
model_id,
Expand Down
1 change: 1 addition & 0 deletions ofscraper/actions/actions/download/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ async def download_picker(username, model_id, medialist, posts):
>= settings.get_threads() * constants.getattr("DOWNLOAD_THREAD_MIN")
)
and settings.not_solo_thread()
and system.platform.system()=="Linux"
):
return await batch.process_dicts(username, model_id, medialist, posts)
else:
Expand Down
2 changes: 1 addition & 1 deletion ofscraper/actions/actions/metadata/batch/metadatabatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def process_dicts(username, model_id, filtered_medialist):
log_threads.append(thread)

processes = [
aioprocessing.AioProcess(
aioprocessing.mp.get_context(system.get_mulitproc_start_type()).Process(
target=process_dict_starter,
args=(
username,
Expand Down
2 changes: 2 additions & 0 deletions ofscraper/actions/actions/metadata/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ async def metadata_picker(username, model_id, medialist):
>= settings.get_threads() * constants.getattr("DOWNLOAD_THREAD_MIN")
)
and settings.not_solo_thread()
and system.platform.system()=="Linux"

):
return batch.process_dicts(username, model_id, medialist)
else:
Expand Down
23 changes: 8 additions & 15 deletions ofscraper/utils/system/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import multiprocess
import psutil
from setproctitle import setproctitle
import aioprocessing



def is_frozen():
Expand Down Expand Up @@ -47,29 +49,20 @@ def getOpenFiles(unique=True):
return out


def set_mulitproc_start_type():
def get_mulitproc_start_type():
plat = platform.system()
if is_frozen():
f_method = "spawn"
multiprocess.set_start_method(f_method)
multiprocessing.set_start_method(f_method)
return f_method
elif plat == "Darwin":
d_method = "spawn"
multiprocess.set_start_method(d_method)
multiprocessing.set_start_method(d_method)
return d_method
elif plat == "Windows":
w_method = "spawn"
multiprocess.set_start_method(w_method)
multiprocessing.set_start_method(w_method)
return w_method
else:
o_method = "forkserver"
multiprocess.set_start_method(o_method)
multiprocessing.set_start_method(o_method)
# additional for mac
if plat == "Darwin":
os.environ["OBJC_DISABLE_INITIALIZE_FORK_SAFETY"] = "YES"
os.environ["no_proxy"] = "*"

o_method = "spawn"
return o_method

def set_eventloop():
plat = platform.system()
Expand Down

0 comments on commit 8e394e8

Please sign in to comment.