How exactly is Python Bytecode Run in CPython?

I am trying to understand how Python works (because I use it all the time!). To my understanding, when you run something like python script.py, the script is converted to bytecode and then the interpreter/VM/CPython–really just a C Program–reads in the python bytecode and executes the program accordingly. How is this bytecode read in? Is it similar to how a text file is read in C? I am unsur

Python Bytecode究竟在CPython中运行得如何?

我想了解Python如何工作(因为我一直都在使用它!)。 据我的理解,当你运行像python script.py这样的脚本时,脚本被转换为字节码,然后解释器/ VM / CPython--实际上就是一个C程序 - 读取python字节码并相应地执行程序。 这个字节码是如何读入的? 它与C中如何读取文本文件类似吗? 我不确定Python代码如何转换为机器代码。 Python解释器(CLI中的python命令)实际上只是一个预编译的C程序,它已经被转换为机器码,然后py

threads and thread in Python

As Wikipedia states : Green threads emulate multi-threaded environments without relying on any native OS capabilities, and they are managed in user space instead of kernel space, enabling them to work in environments that do not have native thread support. Python's threads are implemented as pthreads (kernel threads) , and because of the global interpreter lock (GIL), a Python process onl

线程和Python中的线程

正如维基百科所述 : 绿色线程模拟多线程环境而不依赖任何本机操作系统功能,并且它们在用户空间而不是内核空间中进行管理,从而使它们能够在没有本地线程支持的环境中工作。 Python的线程被实现为pthreads (kernel threads) ,并且由于全局解释器锁定(GIL),Python进程一次只能运行一个线程。 [ 问题 ]但是在Green-threads (或所谓的greenlet或tasklet)的情况下, GIL会影响他们吗? 一次可以运行多个greenlet吗?

Django raising ValueError: invalid literal for int() with base 10 on POST

Django is consistently throwing a ValueError on every POST request to the server. From cruising around forms and SE, it seems like this an issue with my Django models. However, I'm not sure why the models would throw this error or why they would be called by Django since this is thrown in a POST event. View in question: def channel(request, channel): user_form = weblog_userForm(reque

Django引发ValueError:对于int()无效的字面量,POST上的基数为10

Django始终将每个POST请求的ValueError到服务器。 从巡游各种形式和SE,这似乎是我的Django模型的一个问题。 然而,我不确定为什么模型会抛出这个错误,或者为什么他们会被Django调用,因为这是在POST事件中抛出的。 有问题的视图: def channel(request, channel): user_form = weblog_userForm(request.POST or None) if request.method == 'POST' and user_form.is_valid(): nickname = user_form.cleane

No module named 'polls.apps.PollsConfigdjango'; Django project tutorial 2

So, I've been following the tutorial steps here https://docs.djangoproject.com/en/1.9/intro/tutorial02/ and I got to the step where I am supposed to run this command: python manage.py makemigrations polls When I run it, I get this error: python manage.py makemigrations polls Traceback (most recent call last): File "<frozen importlib._bootstrap>", line 2218, in_find_and_load_unlocke

没有名为'polls.apps.PollsConfigdjango'的模块; Django项目教程2

所以,我一直在这里按照教程步骤https://docs.djangoproject.com/en/1.9/intro/tutorial02/和我到了我应该运行此命令的步骤: python manage.py makemigrations polls 当我运行它时,我得到这个错误: python manage.py makemigrations polls Traceback (most recent call last): File "<frozen importlib._bootstrap>", line 2218, in_find_and_load_unlocked AttributeError: 'module' object has no attribute '__p

Django 1.8 migration error with postgres

I am new to Django and I am trying to create table in Postgre using Django(1.8) following is my model class class Student(models.Model): name = models.CharField(max_length = 50) degree = models.CharField(max_length = 50) numofsubs = models.IntegerField() namesofsubs= models.CharField(max_length = 50) details = models.CharField(max_length = 50) class

Django 1.8与postgres迁移错误

我是Django的新手,我正尝试使用Django(1.8)在Postgre中创建表格, 以下是我的模特班 class Student(models.Model): name = models.CharField(max_length = 50) degree = models.CharField(max_length = 50) numofsubs = models.IntegerField() namesofsubs= models.CharField(max_length = 50) details = models.CharField(max_length = 50) class Meta: db_table = "

ImportError at /admin/ in Django 1.9.4

I updated my Django Version to 1.9.4 and now I get an Import Error No module named views when I try to accessthe Admin-URL. django.contrib.admin is included in Installed_Apps in settings.py How to fix this error? The rest of the Django project is working fine. Error log: [26/Mar/2016 12:54:02] "GET /admin/ HTTP/1.1" 500 114684 Internal Server Error: /admin/ Traceback (most r

Django 1.9.4中的/ admin /导入错误

我更新了我的Django版本到1.9.4,现在我得到一个导入错误 No module named views 当我尝试访问Admin-URL时。 django.contrib.admin包含在settings.py中的Installed_Apps中 如何解决这个错误? Django项目的其余部分工作正常。 错误日志: [26 / Mar / 2016 12:54:02]“GET / admin / HTTP / 1.1”500 114684内部服务器错误:/ admin / Traceback(最近调用最后一次):文件“/usr/local/lib/python2.7 /dist-packages/d

spawn performance when capturing process output

I am trying to use posix_spawn instead of fork/exec to get some performance gain. My current project is written in Python, so I used this Python binding. Also I tried some of its forks, and after that I wrote my own posix_spawn binding in Cython (to get rid of some dependencies), but obtained almost the same results. There is indeed a significant speed-up when I just need to run processes wit

捕获过程输出时产生性能

我正在尝试使用posix_spawn而不是fork / exec来获得一些性能增益。 我目前的项目是用Python编写的,所以我使用了这个Python绑定。 此外,我尝试了它的一些分支,之后我在Cython中编写了自己的posix_spawn绑定(以消除一些依赖关系),但获得了几乎相同的结果。 当我只需要在不捕获stdout / stderr的情况下运行进程时,确实有显着的提速。 但是当我确实需要它时(对于我的项目来说这是必要的),posix_spawn调用变得和fork /

threaded Python affected by the GIL

As the GIL is a lock that surrounds the interpreter does it affect compiled Python? I'm wondering whether it is possible to get past the inherent multi-threading limitations of cpython by simply compiling my python before executing it. Hopefully that makes sense and I'm not missing something obvious or misinterpreting how the GIL works/affects execution. Thanks As Daniel said in th

受GIL影响的线程化Python

由于GIL是一个围绕解释器的锁,它会影响编译的Python吗? 我想知道是否有可能通过在执行它之前编译我的python来超越cpython固有的多线程局限性。 希望这是有道理的,我不会错过某些明显或误解GIL如何工作/影响执行的内容。 谢谢 正如丹尼尔在评论中所说,这取决于你如何“编译”代码。 例如,使用Jython运行代码的确可以解决GIL带来的限制。 另一方面,使用像py2exe这样的东西没什么区别,因为它实际上只是将CPython包

PyPy vs Cpython, will either one drop GIL and support POSIX Threads?

Given that the GIL limits pythons ability to support true threads, is it possible to strip it out of current python implementations so that the language can finally support true multithreading. Furthermore, assuming that the GIL is dropped, would that mean that multi-core threading would finally come to scripting/interpreted languages such as Python and Ruby? Your question is flawed. Python s

PyPy vs Cpython,会不会放弃GIL并支持POSIX线程?

鉴于GIL限制pythons支持真正线程的能力,是否有可能将它从当前的python实现中剥离出来,以便语言最终可以支持真正的多线程。 此外,假设GIL被丢弃,这是否意味着多核线程最终会来到像Python和Ruby这样的脚本/解释语言? 你的问题是有缺陷的。 Python支持线程就好了。 事实上,当你在* nix下运行的Python程序中创建一个线程时,它可能会创建一个额外的pthreads线程,而不会提出任何问题。 唯一的限制是Python代码不会并行运

Python GIL and threads synchronization

After having read various articles that explain GIS and threads in Python, and Are locks unnecessary in multi-threaded Python code because of the GIL? which is a very useful answer, I have one "last question". If, ideally, my threads only operate on shared data through atomic (Python VM) instructions, eg appending an item to a list, a lock is not needed, right? That really depends

Python GIL和线程同步

在阅读了各种可以在Python中解释GIS和线程的文章之后,并且由于GIL,在多线程Python代码中锁是不必要的? 这是一个非常有用的答案,我有一个“最后一个问题”。 理想情况下,如果我的线程仅通过原子(Python VM)指令对共享数据进行操作,例如将一个项目附加到列表中,则不需要锁定,对吧? 这真的取决于你的应用程序。 您可能需要锁定您的特定用例,就像使用其他语言一样,但您无需保护python对象无论如何都会被损坏。 从