Brython execution options are not preserved when starting a worker
shlomil opened this issue · comments
While starting a worker with <brython-options cache="true" ...
the executed worker will resolve back to using cache='false' which is the default.
To reproduce use the following example. If you open the dev tools (F12) and switch to the network tab you may totice two requests for some_module.py, while the secons one (from the worker) contains the ?v=[0-9] timestamp in the url :
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<script src="https://raw.githack.com/brython-dev/brython/master/www/src/brython.js"
crossorigin="anonymous">
</script>
<script src="https://raw.githack.com/brython-dev/brython/master/www/src/brython_stdlib.js"
crossorigin="anonymous">
</script>
<brython-options debug="1" cache="true"></brython-options>
</head>
<body>
<script type="text/python" class="webworker" id="worker">
from browser import bind, self
from some_module import some_func
print('worker thread:'+some_func())
@bind(self, "message")
def message(evt):
result = 'pong' if evt.data == 'ping' else evt.data
self.send(result)
</script>
<script type="text/python">
from browser import worker
from some_module import some_func
print('main thread: '+some_func())
def ready(w):
w.send('ping')
def message(ev):
print(ev.data)
worker.create_worker("worker", onready=ready, onmessage=message)
</script>
</body>
</html>
Possible solutions:
- Make create_worker pass the options to the worker startup code and start it with the same options.
- Allow disabging the cache feature from brython code
The commit above should fix this issue. Can you check ?
Tested and now the above code works as expected.
Thank you.