Python全局解释器锁定GIL问题 [英] python Global Interpreter Lock GIL problem

查看:72
本文介绍了Python全局解释器锁定GIL问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在网络上提供一种服务,人们可以测试使用python编写并在linux机器上运行的算法的性能

I want to provide a service on the web that people can test out the performance of an algo, which is written in python and running on the linux machine

基本上我想做的是,有一个非常简单的PHP处理程序,比如说start_algo.php,它接受来自浏览器的请求,并通过system()或popen()在php代码中接受(类似exec("python algo.py"))发布一个运行python脚本的新进程,我认为这在这一部分是可行的

basically what I want to do is that, there is a very trivial PHP handler, let's say start_algo.php, which accepts the request coming from browser, and in the php code through system() or popen() (something like exec( "python algo.py" ) ) to issue a new process running the python script, I think it is doable in this part

问题在于,由于它是一个Web服务,因此它肯定必须同时服务多个用户,但是我对Global Interpreter Lock GIL感到非常困惑.

problem is that since it is a web service, surely it has to serve multiple users at the same time, but I am quite confused by the Global Interpreter Lock GIL http://wiki.python.org/moin/GlobalInterpreterLock that the 'standard' CPython has implemented, does it mean, if I have 3 users running the algo now (which means 3 separated processes, correct me if I am wrong plz), at a particular moment, there is only one user is being served by the Python interpreter and the other 2 are waiting for their turns?

非常感谢

泰德

推荐答案

如果要通过调用新进程来打开每个脚本,请执行以下操作:您不会违反GIL.每个进程都有自己的解释器,因此也有自己的解释器锁.

If you are opening each script by invoking a new process; you will not run afoul of the GIL. Each process gets its own interpreter and therefore its own interpreter lock.

这篇关于Python全局解释器锁定GIL问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆