简体   繁体   English

Udacity Web Python解释器如何工作?

[英]How does Udacity web Python interpreter work?

Udacity gives students a web editor to enter Python programs. Udacity为学生提供了一个Web编辑器来输入Python程序。 The editor recognizes Python keywords and built-in functions and allows to run a program. 编辑器识别Python关键字和内置函数,并允许运行程序。 Do you know how this technology works? 你知道这项技术是如何运作的吗? Are programs submitted to a backend and executed by the standard Python interpreter or is it a JavaScript based Python interpreter? 程序是提交给后端并由标准Python解释器执行还是基于JavaScript的Python解释器? Does the editor simply hold a static list of Python keywords and built-in functions or does it interact with the standard or JavaScript based Python to obtain these? 编辑器是否只是持有Python关键字和内置函数的静态列表,还是与标准或基于JavaScript的Python交互以获取这些?

While javascript python interpreters do exist: http://syntensity.com/static/python.html , they don't appear to be using one. 虽然javascript python解释器确实存在: http//syntensity.com/static/python.html ,但它们似乎没有使用。 It would be far too easy to cheat if they didn't at least run the programs once for verification on their own interpreter. 如果他们至少没有运行一次程序来对自己的翻译进行验证,那就太容易作弊了。

After looking at the network activity on Udacity I can see that they make an ajax call with a bunch of data and then get the results of the program run back in JSON. 在查看Udacity上的网络活动之后,我可以看到他们使用一堆数据进行ajax调用,然后以JSON的形式运行程序的结果。

At a guess they have the standard python interpreter running in a sandbox that will execute the assignments, then the results are packed into JSON, returned to the client and updated to the screen. 猜测他们有一个标准的python解释器在沙盒中运行,它将执行分配,然后将结果打包成JSON,返回给客户端并更新到屏幕。 At the same time the results of your submission will be recorded as part of your class results. 同时,您提交的结果将作为课程结果的一部分进行记录。

Very late to the party here, but I work as an engineer at Udacity, so I figured I'd give it a shot. 很晚到这里聚会,但我作为在Udacity的工程师工作,所以我想我给它一个镜头。

There are two fundamental things going on: 有两个基本的事情发生:

  1. The current syntax highlighting and editing is provided by a Codemirror implementation , although we have used several different editors in the past couple years. 当前语法突出显示和编辑由Codemirror实现提供 ,尽管我们在过去几年中使用了几个不同的编辑器。
  2. When you hit submit (or run), your code is packaged up and shipped off to a sandboxed cluster we run for execution. 当您点击提交(或运行)时,您的代码将被打包并运送到我们运行以执行的沙盒集群中。 If you're hitting submit, this is where we run our own tests against your code and "grade" it to see if it passes. 如果您正在进行提交,那么我们就会针对您的代码运行我们自己的测试并对其进行“评分”以查看它是否通过。 The output from that (in various forms) is piped back to the front end, and you get your feedback. 它的输出(以各种形式)通过管道传送到前端,您将得到您的反馈。

Not quite as fast as running it locally, but it sure beats supporting a few hundred thousand people trying to install Python for the first time ;) 没有在本地运行它那么快,但肯定能够支持数十万人第一次尝试安装Python;)

I haven't tried Udacity, but for the syntax highlighting parts, it can be easily done with a simple backend code, which is updated using some Ajax. 我没有尝试过Udacity,但是对于语法高亮部分,可以使用简单的后端代码轻松完成,后端代码使用一些Ajax进行更新。 One of the easiest ways can be used as lexical analyzing as in compilers or interpreters .. 最简单的方法之一可以用作编译器或解释器中的词法分析。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM