Using reactivex (RxPy) in frappe

Hello All,

I was trying to incorporate GitHub - ReactiveX/RxPY: ReactiveX for Python in frappe custom API call.
I have a list of inputs and those could be executed in parallel.

Sample code snippet
return rx.from_iterable([list of items]).pipe( ops.map(lambda x: test(x)), ops.subscribe_on(scheduler) ).run()

What happens is that in the test method, I am not able to reference frappe.db.sql or frappe.get_doc or frappe.qb.from_.

It seems to me that the context is lost because the test method runs in a different thread.

Is there a workaround possible with this ?

I think you need to frappe.init(site)

check this custom command that start new process and init site.

https://github.com/revant/connect_mqtt/blob/main/connect_mqtt/commands/__init__.py

Thank you for the pointer.