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
Synchronous XMLHttpRequest deprecation fix coming? #188
Comments
Synchrounous requests are used for imports and for the built-in function |
As mentioned in a post on the discusssion group, perhaps the approach used by Skulpt with "suspensions" could be used. https://github.com/skulpt/skulpt/search?utf8=%E2%9C%93&q=suspension |
Interesting thing - As I wrote a couple of weeks ago, I could manage to get a similar mechanism However there are two issues with that:
From skimming the skulpt document, they make teh same thing, but without the Factoring my code out of the old Brython I am usingm and setting it free to So here is the basic idea: def get_json(url, data): The basic idea method works like thus (give or take some try/except, and class Sapore: def call(self, _args, *_kw): def complete(self, response): @sapore do things before async requestserver_data = yield get_json("/get_data", {"mydata": "whatever"}) do things with retrieved ajax data.--And it is that simple. On 15 May 2015 at 07:12, André Roberge notifications@github.com wrote:
|
I'll be taking a look into this ticket since I'd like to work towards async module imports . @jsbueno afaict the scope of this feature should be bound to brython core . What you propose seems to have some impact on python code , which would not be suitable e.g. for module imports . In any case your contribution will be highly appreciated . |
At present , and considering my previous experience , it seems to me that the key factors to consider when implementing async ops are :
p.s. I've been following in python-dev the current draft of async / await PEP and I'm hoping a similar approach will allow us to implement that as well . |
Would implementing the loading of modules via the CommonJS/AMD/requirejs standard yield a solution? Inner code could be wrapped into a function that awaits the loading of all previous modules before executing. For instance, code like, main.py:
would get refactored to something like (pseudo-code):
nested imports could be handled similarly with nested require() functions. The tricky part would be if you had something like this:
In this case, the asynchronous importing of slowImport and fastImport could mean that fastImport.py finishes before slowImport and thus that
to make brython fully cPython compatible, something like this (nested wrappers) should be the default option (and it would raise the proper "NameError" if
or
in any case a wrapper around the import statements so that they return the inner block as a function after require(), or an equivalent async import framework, seems like the only way to get around the inevitable removal of synchronous XHTTP requests. The part that I haven't read the brython code enough to be sure how to do is to make sure that variables defined before the import statement are still available in the inner function. It's not something I've dealt with in my CommonJS coding. |
@mscuthbert Add suport for AMD modules in Brython core is the ultimate destination of the work I'm making to improve the import system . Nevertheless it's not a trivial refactoring . As such we have to improve many things and finish other tickets first e.g. this ticket #188 and maybe #142 and #210 . The main goal of the project in the short term should be running the CPython test suite and improve upon current compatibility as well as regression testing (see #234) . @PierreQuentel cmiiw |
@mscuthbert about your code snippets , these problems are found in Python code as well and they are solved by following the principle better explicit than implicit . |
@olemis sorry if I was read as implying you didn't have a great handle on the problems. I'm sure that with the great work you and others have done on the project that you have a roadmap towards solving it. I was just worried that synchronous support could be dropped any day (a major project of my own was hit when Chrome dropped plugin support in April with hundreds of users depending on it) and I didn't see anywhere a public declaration of the way the work planned to head. I do think that what is explicit to one person can be implicit to another and vice-versa; I'm not sure what is implicit above. But I'm new to trying to contribute so I should have probably listened more before sending in potential directions. Thanks for the kind responses. |
@mscuthbert I apologize in advance if I was rude or something . I just assumed you were following the mailing list and previously read "Port of jQuery UI" thread Jan 14th, 2015 but now I notice this might not be the case . In there I mention that either AMD or UMD might be useful . The former is widely adopted but the later is supposed to work on both browser as well as node.js environments . |
... and FWIW , the purpose of my comment about your code snippets is to emphasize upon the fact that even if async imports are implemented the import statement will still be synchronous , because that's the semantics of Python . On the one hand cases like |
agreed. I've now joined the mailing list and hope to be able to contribute soon. I'm just so amazingly excited by the progress of this project -- I've been wanting to work on Skulpt or pypy.js for some time, but the amount of work still to be done (esp. in speedups) was so daunting; here it seems like enough has been done that adding other components will be a joy to do. Thank you. |
…on source code ... [untested]
…s for Brython AMD tokenizer ... FAIL
…ing it into function invocation ... FAIL Previously, values bound to variables local to tokenize() generator function were polluted by assignments performed elsewhere.
…e , listed below ... FAIL - Append logical line info in new-line tokens - Match new line chars after comments and emit once either NEWLINE or NL - Adjust start/end positions of encoding tokens - Increment row if encoding definition found in second physical line - Do not emit INDENT token after explicit line join lexem - Increment column on matching whitespace
…alues for DEDENT tokens. New line char literals in tokenizer test case definition ... FAIL
…e chars generated for encoding declaration comments
…w line following comment
…nition in function call
…L upon matching of line end markers
…r than NAME). Fix auto-DEDENT position after blank lines ... ok
…rding to browser vs node.js
… using node.js client
…erOptions.baseUrl rather than basePath config option. This change is aimed at running the test suite without requiring patching Intern .
I also find this pretty worrisome. I don't see any real reason to suppose that synchronous XMLHTTPRequest will not eventually be removed, and it seems like if that were to happen Brython would completely break. The approach described by olemis seems pretty promising as far as I understand it. But has it just been abandoned? |
Since these discussions took place, the "async" and "await" syntax has become fully a part of JS and supported by most transpilers. It's should be easy to have python syntax such as:
be compiled into code like:
So long as the original calling function is Promise-aware and brython's JS engine passes Promises around, the worst problems of Synchronous Async can be worked around without much hassle. |
If it was simple, I have no doubt that in 6 years someone would have already implemented it. But it is not so simple : all imports are not performed by a statement Suppose that a module X defines the class A: class A:
def foo(self, x):
import math
return math.sin(x)
def bar(self, x):
return 2 * x If the main module has : import X
a = X.A()
print(a.foo(1))
print(a.bar(2)) the translation of the last 2 lines would have to be something like print(await a.foo(1)) // because of the async "import math" in foo
print(a.bar(2)) // nothing to await How would the Brython engine know, by static code analysis, which calls should use Even more difficult - and totally weird I admit, but it must work, otherwise it's not real Python: Module Y : x = "impo"
y = "rt foobar" Main module: from Y import *
exec(x + y) |
I did not mean to imply that it was simple -- apologies if I did. I just meant to say that I don't think it is the "death knell for the project" if it happened that it might have been if it had happened in 2015. It would be a major pain and difficult agreed and probably need to make every statement become async-await and normal statements return an immediately-resolving Promise, which would be pretty awful. |
Another thing that I forgot to mention is that loading modules with Ajax calls can be avoided if the program uses the Virtual File System in |
When loading http://brython.info/ and looking at the console, I see the following warning:
Is there a planned fix for this? Google has been known to suddenly stop supporting features after giving warnings for a while.
The text was updated successfully, but these errors were encountered: