reflex-dev / reflex

🕸️ Web apps in pure Python 🐍
https://reflex.dev
Apache License 2.0
20.38k stars 1.17k forks source link

[Question] Is there a way to get the same result of 'pc init' by a code command (not by subprocessing and not by command line)? #1500

Open MenachemBerkovich opened 1 year ago

MenachemBerkovich commented 1 year ago

I need to boot the app and other system concurency, and link them by multiprocessing.Manager().Queue().
So my question is if there is a way to do this - running 'pc init' as part of my main module, and passing the shared queue as an argument.

from multiprocessing import Manager
with Manager() as manager:
        # Create a queue within the context of the manager
        q = manager.Queue()

        # Create two instances of the Process class, one for each function
        p1 = Process(target=my_own_process, args=(q,))
        p2 = Process(target=pynecone_process, args=(q,)) #? there is such a target / function / method to boot pynecone_process (with argument like queue to deal with it after in app's modules)?

        # Start both processes
        p1.start()
        p2.start()

        # Wait for both processes to finish
        p1.join()
        p2.join()

Specifics (please complete the following information):

Thank you!

masenf commented 1 year ago

@MenachemBerkovich you might have a look at the AppHarness i added for integration testing of reflex apps: https://github.com/reflex-dev/reflex/blob/919f239168d789056dfca6c67a500637f3f0ab8e/reflex/testing.py#L143

i don't know if it quite does what you want, but it supports calling init and starting the backend server inside the same process programmatically. (The frontend is a nodejs process, so it has to be a subprocess)

At any rate, it might inspire an idea of what is possible.

Programmatic invocation is something we're trying to work out to enable better debuggability of reflex apps.

MenachemBerkovich commented 1 year ago

Thanks @masenf, And for 'reflex run'? Is there an accesible method?