Since the data previously collected in the hospital were prescription pictures obtained by taking photos, what needs to be used is the text form of the prescription. Therefore, I wrote a small program in the past two weeks to display pictures of the server to users (hiring some people at that time), allowing users to enter text information based on the pictures.
I used Java to write web pages before. I thought that I would use Python to learn machine learning recently, so I used Python to write it. In addition, because I wanted to use something new and the program was relatively small, I considered using mongodb for storage. (Although it's really not necessary).
The basic architecture is like this: (backend language) python + (web framework and web server) tornado + (database) mongodb + (process management) supervisor + (reverse proxy) nginx
(1) python: I am watching Liao Xuefeng’s python tutorial
I learned some basic sentences, and then I checked them if I didn’t understand them when I was doing them.
(2) tornado: I started learning by watching this tutorial
tornado is very fast to use. It can map requests directly like a forwarder in spring, and directly monitor http requests on a certain port like tomcat. Tornado has done all these things for us, we only need to write The get and post methods are fine.
The rest is almost the same as in java web. Without the framework of springMVC and hibernate, you can layer controller, service, and dao in the python package yourself.
(3) mongodb: Non-relational database, there is no requirement for the same field name to be unified for each row of data (called collection in mongodb) in a table (called collection in mongodb). More or less, uneven. Another point is that transactions are not supported, and there is no way to roll back when executing multiple read and write statements in Python, so you have to find a way to prevent problems caused by concurrency in the program.
For example, I need to find a document with a status of 0 from the collection and update it to 1, which means the user is viewing it. After the user makes modifications, then set the status to 2 and then put it back. Here 0 means not browsed, 1 It means it is being browsed, and 2 means it has been modified. At this time, many users may have obtained the data with status 0 at the same time. This goes against our wishes and allows many people to modify the same data. You can consider directly update_one to change the status of a document from 0 to 1, and then add a unique field to identify the document, and use this unique field to find the document. At this time, other users cannot obtain the document because update_one It will be locked when the time comes, and others cannot get this data.
(4) supervisor: Supervisor is a process management program developed in python. It can turn ordinary commands into background daemons and monitor the process status.
After installation, you can add the configuration file printprescription.conf in the /etc/supervisor/conf.d directory. The configuration example is as follows
[program:printprescription] #设置守护进程名 command = python /home/liaohuqiang/Code/printprescription/main2.py #设置执行命令 autorstart=true #设置随supervisor的启动而启动 stdout_logfile = /home/liaohuqiang/Code/printprescription/printprescription.log #设置日志路径
After the configuration is completed, you can open, close and restart the supervisor service. You can use supervisorctl status to check the process status, and you can also check the error information in the relevant log files
sudo /etc/init.d/supervisor start sudo /etc/init.d/supervisor stop sudo /etc/init.d/supervisor restart<br><br>sudo supervisorctl status printprescripton<br>vim cat /var/log/supervisor/xxx.log
(5) nginx: nginx is used as a reverse proxy. It can monitor port 80 and forward corresponding requests to other hosts and other ports. The path of the image we display here is not in tornado in static (static is used to store front-end static resources such as js and css), but in another location on the server, so the image can be obtained through nginx forwarding. On the other hand, other ports (such as the 8001 port that tornado listens on) are generally not exposed to users, so nginx is used for forwarding. In addition, the location /static/ directive tells nginx to provide static directory files directly instead of proxying requests to tornado. nginx can provide static files more efficiently than tornado.
After installing nginx, check the relevant configuration files and find this sentence: include /etc/nginx/sites-enabled/*. You can create a new configuration file in this directory for configuration
cat /etc/nginx/nginx.conf<br>sudo touch /etc/nginx/sites-enabled/default2
The configuration example is as follows. It should be noted that the bottom http://127.0.0.1:8001/ If the last slash here is not typed, the above printprescription will actually be added. When the user accesses "host/printprescription" It is equivalent to accessing "Host:8001/printprescription". Since the request on Tornado is mapped to Host:8001/, 404 will appear at this time.
<span style="color: #000000"> upstream frontends { server </span><span style="color: #800080">222.222</span>.<span style="color: #800080">222.222</span>:<span style="color: #800080">8000</span><span style="color: #000000">; server </span><span style="color: #800080">222.222</span>.<span style="color: #800080">222.222</span>:<span style="color: #800080">8001</span><span style="color: #000000">; } server { listen </span><span style="color: #800080">80</span><span style="color: #000000">; location </span>/<span style="color: #000000"> { proxy_read_timeout </span><span style="color: #800080">1800</span><span style="color: #000000">; proxy_pass_header Server; proxy_set_header Host $http_host; proxy_redirect off; proxy_set_header X</span>-Real-<span style="color: #000000">IP $remote_addr; proxy_set_header X</span>-<span style="color: #000000">Scheme $scheme; proxy_pass http:</span><span style="color: #008000">//</span><span style="color: #008000">frontends;</span> <span style="color: #000000"> } location </span>/doctorAfter/<span style="color: #000000"> { #配置图片路径 root </span>/home/<span style="color: #000000">wenserver; } location </span>/static/<span style="color: #000000"> { #配置前端静态资源路径 root </span>/home/xxx/Code/printprescription/<span style="color: #000000">view; } location </span>/printprescription/<span style="color: #000000"> { proxy_read_timeout </span><span style="color: #800080">1800</span><span style="color: #000000">; proxy_pass_header Server; proxy_set_header Host $http_host; proxy_redirect off; proxy_set_header X</span>-Real-<span style="color: #000000">IP $remote_addr; proxy_set_header X</span>-<span style="color: #000000">Scheme $scheme; proxy_pass http:</span><span style="color: #008000">//</span><span style="color: #008000">127.0.0.1:8001/;</span> <span style="color: #000000"> } }</span>
(6)opencv:一个计算机视觉库,实现了图像处理和计算机视觉方面的很多通用算法。由于之前采集数据的时候在处方图片数据中混杂了人脸图片,所以采用oepncv里的算法检测人脸,如果是人脸则删除该记录。然而还是会残留一些人脸图片,需要人工清洗,这个数据好像之前有师兄清洗过,到时候拿过来重构一下数据库。
ps:安装opencv的时候imshow报错,虽然imshow用不到,但是强迫症使然,搞了我一天,来来回回装了十多次,最后还是没搞定,真是心力交瘁,特想吐嘈:垃圾opencv!毁我青春!颓我精神!耗我时间!磨我意志!浪费人生!!!
好吧我就随便说说,回头还要靠它干活。
cv2.error: /io/opencv/modules/highgui/src/window.<span style="color: #0000ff">cpp</span>:<span style="color: #800080">583</span>: error: (-<span style="color: #800080">2</span>) The <span style="color: #0000ff">function</span> is not implemented. Rebuild the library with Windows, GTK+ <span style="color: #800080">2</span>.x or Carbon support. If you are on Ubuntu or Debian, <span style="color: #0000ff">install</span> libgtk2.<span style="color: #800080">0</span>-dev and <span style="color: #0000ff">pkg-config</span>, <span style="color: #0000ff">then</span> re-run cmake or configure script <span style="color: #0000ff">in</span> <span style="color: #0000ff">function</span> cvShowImage
The above is the detailed content of python+tornado+supervisor+nginx deployment under ubuntu. For more information, please follow other related articles on the PHP Chinese website!

Python and C each have their own advantages, and the choice should be based on project requirements. 1) Python is suitable for rapid development and data processing due to its concise syntax and dynamic typing. 2)C is suitable for high performance and system programming due to its static typing and manual memory management.

Choosing Python or C depends on project requirements: 1) If you need rapid development, data processing and prototype design, choose Python; 2) If you need high performance, low latency and close hardware control, choose C.

By investing 2 hours of Python learning every day, you can effectively improve your programming skills. 1. Learn new knowledge: read documents or watch tutorials. 2. Practice: Write code and complete exercises. 3. Review: Consolidate the content you have learned. 4. Project practice: Apply what you have learned in actual projects. Such a structured learning plan can help you systematically master Python and achieve career goals.

Methods to learn Python efficiently within two hours include: 1. Review the basic knowledge and ensure that you are familiar with Python installation and basic syntax; 2. Understand the core concepts of Python, such as variables, lists, functions, etc.; 3. Master basic and advanced usage by using examples; 4. Learn common errors and debugging techniques; 5. Apply performance optimization and best practices, such as using list comprehensions and following the PEP8 style guide.

Python is suitable for beginners and data science, and C is suitable for system programming and game development. 1. Python is simple and easy to use, suitable for data science and web development. 2.C provides high performance and control, suitable for game development and system programming. The choice should be based on project needs and personal interests.

Python is more suitable for data science and rapid development, while C is more suitable for high performance and system programming. 1. Python syntax is concise and easy to learn, suitable for data processing and scientific computing. 2.C has complex syntax but excellent performance and is often used in game development and system programming.

It is feasible to invest two hours a day to learn Python. 1. Learn new knowledge: Learn new concepts in one hour, such as lists and dictionaries. 2. Practice and exercises: Use one hour to perform programming exercises, such as writing small programs. Through reasonable planning and perseverance, you can master the core concepts of Python in a short time.

Python is easier to learn and use, while C is more powerful but complex. 1. Python syntax is concise and suitable for beginners. Dynamic typing and automatic memory management make it easy to use, but may cause runtime errors. 2.C provides low-level control and advanced features, suitable for high-performance applications, but has a high learning threshold and requires manual memory and type safety management.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment