I have a TKinter program that awaits stdin and then does an action based on the stream of inputs. Then I have a node.js program that scrapes a webpage every hour and based on that, writes to stdout. Is there a way I can set up these two processes to communicate with each other in real time?
-
Are you able to change a logic a bit an use file for your needs instead of i/o?...or you can use redis or something like thatDmytro Huz– Dmytro Huz2020-04-18 22:13:07 +00:00Commented Apr 18, 2020 at 22:13
-
@DmytroHuz because that's very inefficient and requires a setup (or a service subscription).Michał Karpacki– Michał Karpacki2020-04-19 21:36:28 +00:00Commented Apr 19, 2020 at 21:36
1 Answer
You can use the python-bridge module that I found some time ago in a similar situation and execute some python code from node. The module will keep a python process for you that you'll be able to call directly from node and you'll also get your arguments translated to python (with deep references, which is quite cool).
It has a nice Promise and template string based API so you can use it in an async function:
await python.ex`import somemodule`
await python.ex`someFunction(${javascripArgument})`
I actually used that in one of my modules, but it's currently not operational (there are some errors that I need to understand, since it used to work) - but see these lines in scramjet-python-module.
The only remark I have that this module hasn't been updated in a year, but it doesn't seem that it'd need to - it seems safe to use to me.