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

multiprocess #77

Open
wants to merge 1 commit into
base: issues/73
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 4 additions & 18 deletions cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import asyncio
import logging
import argparse
import multiprocessing

import wiji
from cli import utils
Expand Down Expand Up @@ -99,10 +100,6 @@ def main():
logger.log(logging.INFO, {"event": "wiji.cli.main", "stage": "end"})


from multiprocessing import Process
from threading import Thread


def start_loop(coro):
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when using multi-processing, I do not think we need to;

loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)

I think we can just do;

asyncio.run( per_process_main())

loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
Expand Down Expand Up @@ -143,25 +140,14 @@ async def async_main(logger: wiji.logger.BaseLogger, app_instance: wiji.app.App)
workers.append(_worker)

del _queue_names
consumers = []
for i in workers:
consumers.append(i.consume_tasks())

# for csm in consumers:
# import pdb

# pdb.set_trace()
t = Process(
p = multiprocessing.Process(
target=start_loop,
args=(i.consume_tasks(),),
name="Process-<wiji_cli-{0}>".format(i.the_task.queue_name),
)
t.start()

gather_tasks = asyncio.gather(
*watch_dog_producer, utils.sig._signal_handling(logger=logger, workers=workers)
)
await gather_tasks
# 0.1094 tasks/sec
p.start()


if __name__ == "__main__":
Expand Down