I have one python script that is used for reading data form COM port and storing the same data in MongoDB. On the other side there is Flask server that is used for displaying data from same database on web page. They are working separately without any problem. Is there any way to merge this two programs, like multithreading in python and how to manage this transformation? If needed, I can provide source code for both programs.
Asked
Active
Viewed 103 times
1
-
You can do this easily, the question is why do you want to do this? The architecture seems fine, two unrelated scripts, one for reading data, one for writing. This is not a good question, because it is hard to tell what you should do, because we have not enough information or it is opinion based. – Frieder Feb 18 '20 at 11:28
-
Well I'm trying to merge these scripts because that is one of the requirements for my student project. When I'm starting the whole thing I need to run everything separately so I'm trying to merge everything and run it from same spot, with only one action. – Mr Menthol Feb 18 '20 at 11:38
-
Do you want to run two python scripts at the same time with a single click? Why do you want merge two unrelated scripts? If you want to run them at the same time, simply use bash script as follows, python COM_port_read.py & python flask_read.py & – Jeeva Bharathi Feb 18 '20 at 11:40
-
Data on COM port is from measurement and its one string of data. This data represents some measurement from measurement. First script is used for reading, formating and storing data in database. Second one is Flask server that is using data from same database. – Mr Menthol Feb 18 '20 at 11:46
1 Answers
0
From my understanding, you want to run two python scripts at the same time.
Simply create a bash script with following text, (replace script1 & script 2 with file names)
python script1.py &
python script2.py &

Jeeva Bharathi
- 514
- 4
- 22
-
1One script is writhing in database and second one is reading from same database. Is there any chance of conflict if both scrips are trying to use database in same time? – Mr Menthol Feb 18 '20 at 11:50
-
MongoDB support multiple thousands of concurrent connection. Since this is a student project as you mentioned in the comment, it should pose no problem. If you want to increase maximum connections allowed to MongoDB, follow this: https://stackoverflow.com/questions/16713415/mongodb-increasing-max-connections-in-mongodb – Jeeva Bharathi Feb 18 '20 at 11:52