-
Notifications
You must be signed in to change notification settings - Fork 95
Multi-context execution (py.Context) #144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
81 commits
Select commit
Hold shift + click to select a range
fc66b7f
py.CompileMode now a string enum
d10c35f
addressed benign Go warnings
2161b71
make Float implement M__index__
247ec42
added string helper functions
9a75271
updated to 1.15
90a8988
new Ctx-aware module model
c51644e
py.Ctx model allows concurrent execution
7f7d213
repl.New() now accepts an existing py.Ctx
708bb7e
fixed typo in callInternal()
a244256
unbroke test compatibilty
75d8743
cleaned up py.Ctx initialization wrt sys and DefaultCtxOpts()
d5fb8e8
added multi Ctx benchmark
269bdc0
WIP
4db9c65
fixed py.NewCtx not being set
53d05db
fixed List.sort() detection of instance invocation
7fd1c29
separated path resolution from path evaluation
8f3a104
removed cruft
5ebaf66
place ctx at top
d423190
err msg tweak
drew-512 b33c266
typo fix
drew-512 efca761
for loops we can all agree on
drew-512 1569475
removed outdated comments
a9c5f1f
Merge branch 'master' of https://github.com/drew-512/gpython
6372aee
added info for Frame.Ctx
4af4f90
removed unnecessary assignment
aec59f8
copyright and formatting
74f1a19
Ctx and NewCtx docs
8fa6622
switch cleanup
26fb9aa
leaner ModuleImpl schema
8614aeb
added GetDict() impl
86531c6
Compile() now returns py.Code (vs py.Object)
f71b961
tighter py.Ctx invocation patterns
77a7954
WIP
6bba7da
reverted to 644
46d1052
chmod 644
66fad23
enhanced RunFile() to enclose RunInNewModule()
95afd7b
Update examples/multi-ctx/main.go
drew-512 319edb7
Update modules/runtime.go
drew-512 06a2eae
Update modules/runtime.go
drew-512 8d4d586
Update modules/runtime.go
drew-512 d475e67
Update vm/eval.go
drew-512 6afac99
Update py/run.go
drew-512 931c346
Update modules/runtime.go
drew-512 a7ce4bb
Update modules/runtime.go
drew-512 c1f8809
Update modules/runtime.go
drew-512 9f02cf1
Update modules/runtime.go
drew-512 85e3a4a
Update modules/runtime.go
drew-512 fbec34e
Update modules/runtime.go
drew-512 dbd54d8
code cleanuo
71a5604
Module doc str
634823c
consistent arg order of NewFunction
6a0c11e
license and formatting
6242836
comment and cruft cleanup
61c7830
renamed Store to ModuleStore + docs
bb98aa8
added import docs
36b1018
shadowing cleanup
f2602bc
docs tweaks
e25e3bb
code cleanup
9421b6b
synced with gpython
92aed8a
Merge branch 'go-python:master' into master
drew-512 96515ea
Update modules/runtime.go
drew-512 f62f2b7
Update modules/runtime.go
drew-512 3bdba62
reverted from %w to %v (linux CI compile failure)
8033615
renamed py.Ctx to py.Context
681abf2
added Context.Close() and ModuleImpl.OnContextClosed()
7508556
docs and LoadIntsFromList
99bcb40
rename edits
0cc7650
push/popBusy now private
9afb2d3
doc edits
7d2a8d9
fixed kwarg issues in ParseTupleAndKeywords() and builtin_print test
ba7db80
added Flush kwarg to print test
61e42c8
added embedding example
168c337
main README makeover
2b7e1ab
fixed type conversion
3821b4b
Update README.md
drew-512 170f0d2
Update README.md
drew-512 b68b9f6
Update py/util.go
drew-512 759023b
Update py/util.go
drew-512 0c77716
Update py/util.go
drew-512 505755d
LoadIntsFromList cleanup
02d6b3e
comment edits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,6 @@ __pycache__ | |
cover.out | ||
/junk | ||
/dist | ||
|
||
examples/embedding/embedding | ||
builtin/testfile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Launch file", | ||
"type": "go", | ||
"request": "launch", | ||
"mode": "debug", | ||
"program": "${file}" | ||
}, | ||
{ | ||
"name": "examples/embedding", | ||
"type": "go", | ||
"request": "launch", | ||
"mode": "auto", | ||
"program": "${workspaceFolder}/examples/embedding", | ||
"cwd": "${workspaceFolder}/examples/embedding", | ||
"args": [ | ||
"mylib-demo.py" | ||
], | ||
}, | ||
] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,18 +5,20 @@ | |
[](https://godoc.org/github.com/go-python/gpython) | ||
[](https://github.com/go-python/gpython/blob/master/LICENSE) | ||
|
||
gpython is a part re-implementation / part port of the Python 3.4 | ||
interpreter to the Go language, "batteries not included". | ||
|
||
It includes: | ||
|
||
* runtime - using compatible byte code to python3.4 | ||
* lexer | ||
* parser | ||
* compiler | ||
gpython is a part re-implementation, part port of the Python 3.4 | ||
interpreter in Go. Although there are many areas of improvement, | ||
it stands as an noteworthy achievement in capability and potential. | ||
|
||
gpython includes: | ||
|
||
* lexer, parser, and compiler | ||
* runtime and high-level convenience functions | ||
* multi-context interpreter instancing | ||
* easy embedding into your Go application | ||
* interactive mode (REPL) ([try online!](https://gpython.org)) | ||
|
||
It does not include very many python modules as many of the core | ||
|
||
gpython does not include many python modules as many of the core | ||
modules are written in C not python. The converted modules are: | ||
|
||
* builtins | ||
|
@@ -27,53 +29,52 @@ modules are written in C not python. The converted modules are: | |
|
||
## Install | ||
|
||
Gpython is a Go program and comes as a single binary file. | ||
|
||
Download the relevant binary from here: https://github.com/go-python/gpython/releases | ||
Download directly from the [releases page](https://github.com/go-python/gpython/releases) | ||
|
||
Or alternatively if you have Go installed use | ||
Or if you have Go installed: | ||
|
||
go get github.com/go-python/gpython | ||
|
||
and this will build the binary in `$GOPATH/bin`. You can then modify | ||
the source and submit patches. | ||
go install github.com/go-python/gpython | ||
|
||
## Objectives | ||
|
||
Gpython was written as a learning experiment to investigate how hard | ||
gpython started as an experiment to investigate how hard | ||
porting Python to Go might be. It turns out that all those C modules | ||
are a significant barrier to making a fully functional port. | ||
are a significant barrier to making gpython a complete replacement | ||
to CPython. | ||
|
||
## Status | ||
However, to those who want to embed a highly popular and known language | ||
into their Go application, gpython could be a great choice over less | ||
capable (or lesser known) alternatives. | ||
|
||
The project works well enough to parse all the code in the python 3.4 | ||
distribution and to compile and run python 3 programs which don't | ||
depend on a module gpython doesn't support. | ||
## Status | ||
|
||
See the examples directory for some python programs which run with | ||
gpython. | ||
gpython currently: | ||
- Parses all the code in the Python 3.4 distribution | ||
- Runs Python 3 for the modules that are currently supported | ||
- Supports concurrent multi-interpreter execution ("multi-context") | ||
|
||
Speed hasn't been a goal of the conversions however it runs pystone at | ||
about 20% of the speed of cpython. The pi test runs quicker under | ||
gpython as I think the Go long integer primitives are faster than the | ||
about 20% of the speed of CPython. The [π test](https://github.com/go-python/gpython/tree/master/examples/pi_chudnovsky_bs.py) runs quicker under | ||
gpython as the Go long integer primitives are likely faster than the | ||
Python ones. | ||
|
||
There are many directions this project could go in. I think the most | ||
profitable would be to re-use the | ||
[grumpy](https://github.com/grumpyhome/grumpy) runtime (which would mean | ||
changing the object model). This would give access to the C modules | ||
that need to be ported and would give grumpy access to a compiler and | ||
interpreter (gpython does support `eval` for instance). | ||
@ncw started gpython it in 2013 and work on is sporadic. If you or someone | ||
you know would be interested to take it futher, it would be much appreciated. | ||
|
||
## Getting Started | ||
|
||
I (@ncw) haven't had much time to work on gpython (I started it in | ||
2013 and have worked on it very sporadically) so someone who wants to | ||
take it in the next direction would be much appreciated. | ||
The [embedding example](https://github.com/go-python/gpython/tree/master/examples/embedding) demonstrates how to | ||
easily embed and invoke gpython from any Go application. | ||
Comment on lines
+66
to
+67
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rather prefer having the |
||
|
||
## Limitations and Bugs | ||
Importantly, gpython is able to run multiple interpreter instances simultaneously, | ||
allowing you to embed gpython naturally into your Go application. This makes it | ||
possible to use gpython in a server situation where complete interpreter | ||
independence is an absolute requirement. See this in action in the [multi-context example](https://github.com/go-python/gpython/tree/master/examples/multi-context) | ||
|
||
If you are looking to get involved, a light and easy place to start is adding more convenience functions to [py/util.go](https://github.com/go-python/gpython/tree/master/py/util.go). See [notes.txt](https://github.com/go-python/gpython/blob/master/notes.txt) for bigger ideas. | ||
|
||
Lots! | ||
|
||
## Similar projects | ||
## Other Projects of Interest | ||
|
||
* [grumpy](https://github.com/grumpyhome/grumpy) - a python to go transpiler | ||
|
||
|
@@ -86,5 +87,5 @@ or on the [Gophers Slack](https://gophers.slack.com/) in the `#go-python` channe | |
## License | ||
|
||
This is licensed under the MIT licence, however it contains code which | ||
was ported fairly directly directly from the cpython source code under | ||
was ported fairly directly directly from the CPython source code under | ||
the [PSF LICENSE](https://github.com/python/cpython/blob/master/LICENSE). |
Empty file.
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd remove this file.