Doc.save() never returns when executed from Subprocess

Hi Guys,

I have the following scenario:
I start a new subprocess in an on_validate function of a doctype.

The process I start is an additional bench command. Within that command, I load a doc and modify it. Problem is that once I call save() on it, the call just blocks and never returns.

When I call the bench command directly from the console it works just fine. I can modify the doc and save it.

It seems like that for whatever reason:

cmd = “bench --site testsite testdbaccess”
cmds = shlex.split(cmd)
process = subprocess.Popen(cmds, start_new_session=True)

behaves differently as if I call it directly from the console.

Any ideas?

Thanks!

This is most likely because it’s waiting on some kind of DB lock which parent process’s db connection holds. Can’t tell much without looking at actual code though.

I don’t think using subprocess like this is a good idea. Look into background jobs instead or do it synchronously.

Yes, I found out that it works for all methods in frappe.db namespace, like frappe.db.set_value - however not on document level.