Speak now
Please Wait Image Converting Into Text...
Embark on a journey of knowledge! Take the quiz and earn valuable credits.
Challenge yourself and boost your learning! Start the quiz now to earn credits.
Unlock your potential! Begin the quiz, answer questions, and accumulate credits along the way.
General Tech Bugs & Fixes 2 years ago
Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.
Turn Your Knowledge into Earnings.
I have been trying to communicate between Node JS and Python following this tutorial: http://www.sohamkamani.com/blog/2015/08/21/python-nodejs-comm/
The python file reads a javascript array and prints the sum using the numpy module. Here is the code for both the python and node js file.
Python code:
import sys, json, numpy as np #Read data from stdin def read_in(): lines = sys.stdin.readlines() return json.loads(lines[0]) def main(): #get our data as an array from read_in() lines = read_in() #create a numpy array np_lines = np.array(lines) #use numpys sum method to find sum of all elements in the array lines_sum = np.sum(np_lines) #return the sum to the output stream print lines_sum #start process if __name__ == '__main__': main()
Node js code:
var spawn = require('child_process').spawn, py =spawn('python', ['compute_input.py']), data = [1,2,3,4,5,6], dataString=''; py.stdout.on('data', function(data) { dataString += data.toString(); }); py.stdout.on('end', function() { console.log('Sum = ', dataString); }); py.stdin.write(JSON.stringify(data)); py.stdin.end();
Error message:
Error: write EPIPE at exports._errnoException (util.js:1018:11) at Socket._writeGeneric (net.js:711:26) at Socket._write (net.js:730:8) at doWrite (_stream_writable.js:331:12) at writeOrBuffer (_stream_writable.js:317: REPLY 0 views 0 likes 0 shares Facebook Twitter Linked In WhatsApp
The Python script is throwing an error. The python command invoked python3 instead of python 2.7, for which the script was written and the script errored out. EPIPE error is thrown because the python script ended prematurely and node tries to read-from/write-to to an already closed pipe.
python
EPIPE
No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.
General Tech 10 Answers
General Tech 7 Answers
General Tech 3 Answers
General Tech 9 Answers
General Tech 2 Answers
Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.