Intermittent bug with asyncio and MS Edge
Hi all
I have a strange intermittent bug.
The role-players -
asyncio on Python 3.8 running on Windows 10
Microsoft Edge running as a browser on the same machine
The bug does not occur with Python 3.7.
It does not occur with Chrome or Firefox.
It does not occur when MS Edge connects to another host on the network,
running the same Python program (Python 3.8 on Fedora 31).
The symptoms -
On receiving a connection, I send an HTML page to the browser,
which has 20 lines like this -
...
Intermittently, one or other of the script files is not received by MS Edge.
I have checked the Network tab in Developer Tools in MS Edge. It shows
the first few requests getting a Status 200 OK, then some are shown as
'Pending'. This seems to be where the problem occurs.
I am hoping that someone can give me some hints about how to debug this.
My function to send the script file looks like this -
async def send_file(writer, fname):
status = 'HTTP/1.1 200 OK\r\n'
writer.write(status.encode())
headers = []
headers.append(('CONNECTION', 'keep-alive'))
headers.append(('DATE',
email.utils.formatdate(usegmt=True)))
headers.append(('SERVER',
f'Python {sys.version.split()[0]} asyncio'))
headers.append(('Content-type', 'text/javascript'))
headers('Transfer-Encoding', 'chunked'))
for key, val in headers:
writer.write(f'{key}: {val}\r\n'.encode())
writer.write('\r\n'.encode())
await writer.drain()
with open(fname 'rb') as fd:
chunk = fd.read(8192)
while chunk:
writer.write(hex(len(chunk))[2:].encode() + b'\r\n')
writer.write(chunk + b'\r\n')
await writer.drain()
chunk = fd.read(8192)
writer.write(b'0\r\n\r\n')
await writer.drain()
writer.close()
await writer.wait_closed()
I have asked the same question on StackOverflow, from an MS Edge
perspective -
https://stackoverflow.com/questions/60785767/ms-edge-randomly-does-not-load-script
I don't know whether the problem lies with Python or MS Edge, but as it
does not happen with Python 3.7, I am suspecting that something changed
in 3.8 which does not match MS Edge's expectations.
Any hints much appreciated.
Frank Millman
--
https://mail.python.org/mailman/listinfo/python-list
inheriting from long on Python2 or int on Python3
Hello, I have a class I wrote for Python2 that needs to be made to work on Python3. On Python2 it inherited from long, so it needs to inherit from int on Python3. The following works, but I'm not sure it's the cleanest solution. It's the first time I've wanted / needed to make a parent class conditional on the Python version, and I'm not sure it's even a good idea. I used inheritance because I wanted to perform bitwise operations on instances, but I could probably switch to composition. Just wondering how bad the following really is (in a code smell kind of a away). TIA. Duncan import sys class C_hash(int if sys.version_info.major >= 3 else long): def __new__(cls, bits, m, N=1): obj = super(C_hash, cls).__new__(cls, bits) obj._m = m obj._N = N return obj -- https://mail.python.org/mailman/listinfo/python-list
Re: Intermittent bug with asyncio and MS Edge
> On 21 Mar 2020, at 13:43, Frank Millman wrote:
>
> Hi all
>
> I have a strange intermittent bug.
>
> The role-players -
>asyncio on Python 3.8 running on Windows 10
>Microsoft Edge running as a browser on the same machine
>
> The bug does not occur with Python 3.7.
> It does not occur with Chrome or Firefox.
> It does not occur when MS Edge connects to another host on the network,
> running the same Python program (Python 3.8 on Fedora 31).
>
> The symptoms -
>On receiving a connection, I send an HTML page to the browser,
>which has 20 lines like this -
>
>
>
>...
>
> Intermittently, one or other of the script files is not received by MS Edge.
>
> I have checked the Network tab in Developer Tools in MS Edge. It shows the
> first few requests getting a Status 200 OK, then some are shown as 'Pending'.
> This seems to be where the problem occurs.
>
> I am hoping that someone can give me some hints about how to debug this.
>
> My function to send the script file looks like this -
>
>async def send_file(writer, fname):
>
>status = 'HTTP/1.1 200 OK\r\n'
>writer.write(status.encode())
>
>headers = []
>headers.append(('CONNECTION', 'keep-alive'))
>headers.append(('DATE',
>email.utils.formatdate(usegmt=True)))
>headers.append(('SERVER',
> f'Python {sys.version.split()[0]} asyncio'))
>headers.append(('Content-type', 'text/javascript'))
>headers('Transfer-Encoding', 'chunked'))
>for key, val in headers:
>writer.write(f'{key}: {val}\r\n'.encode())
>writer.write('\r\n'.encode())
>await writer.drain()
>
>with open(fname 'rb') as fd:
>chunk = fd.read(8192)
>while chunk:
>writer.write(hex(len(chunk))[2:].encode() + b'\r\n')
>writer.write(chunk + b'\r\n')
>await writer.drain()
>chunk = fd.read(8192)
>writer.write(b'0\r\n\r\n')
>await writer.drain()
>
>writer.close()
>await writer.wait_closed()
>
> I have asked the same question on StackOverflow, from an MS Edge perspective -
> https://stackoverflow.com/questions/60785767/ms-edge-randomly-does-not-load-script
>
> I don't know whether the problem lies with Python or MS Edge, but as it does
> not happen with Python 3.7, I am suspecting that something changed in 3.8
> which does not match MS Edge's expectations.
I'd look at the network traffic with wireshark to see if there is anything
different between edge and the other browsers.
Aside: headers are case blind, but usually written capitalised. Some buggy
software expects that its capitalised.
I wonder if it will start working if you do not do chunked (your chunked
encoding looks correct).
You can use os.stat to find the size of the file for the Content-Length header.
Barry
>
> Any hints much appreciated.
>
> Frank Millman
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
--
https://mail.python.org/mailman/listinfo/python-list
Re: inheriting from long on Python2 or int on Python3
On Sun, Mar 22, 2020 at 4:21 AM duncan smith wrote: > > Hello, > I have a class I wrote for Python2 that needs to be made to work > on Python3. On Python2 it inherited from long, so it needs to inherit > from int on Python3. The following works, but I'm not sure it's the > cleanest solution. It's the first time I've wanted / needed to make a > parent class conditional on the Python version, and I'm not sure it's > even a good idea. I used inheritance because I wanted to perform bitwise > operations on instances, but I could probably switch to composition. try: int = long except NameError: pass Then just inherit from int. On Py3 it'll just work fine, and you can drop those two lines of code once you drop Py2 support. On Py2 (which is becoming less and less important now), it'll do that assignment. Alternatively, don't worry about Py2 any more, and just change it to inherit from it. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: inheriting from long on Python2 or int on Python3
> import sys > > class C_hash(int if sys.version_info.major >= 3 else long): ... There's nothing incorrect with your solution. Chris offered another. I was going to suggest you consider running your code through 2to3 to see what it does. I created a C_hash class similar to yours: class C_hash(long): def __new__(cls, bits, m, N=1): obj = super(C_hash, cls).__new__(cls, bits) obj._m = m obj._N = N return obj def meth(self): pass When I ran it through 2to3, it didn't make any transformations, which I thought odd. Still, assuming I did something wrong, you might poke around with it a bit to see if you can get it to do the work for you. Skip -- https://mail.python.org/mailman/listinfo/python-list
Re: inheriting from long on Python2 or int on Python3
On 21/03/2020 21:55, Skip Montanaro wrote: >> import sys >> >> class C_hash(int if sys.version_info.major >= 3 else long): > ... > > There's nothing incorrect with your solution. Chris offered another. I > was going to suggest you consider running your code through 2to3 to > see what it does. I created a C_hash class similar to yours: > > class C_hash(long): > def __new__(cls, bits, m, N=1): > obj = super(C_hash, cls).__new__(cls, bits) > obj._m = m > obj._N = N > return obj > > def meth(self): > pass > > When I ran it through 2to3, it didn't make any transformations, which > I thought odd. Still, assuming I did something wrong, you might poke > around with it a bit to see if you can get it to do the work for you. > > Skip > According to the docs (https://docs.python.org/2/library/2to3.html) it should have renamed long to int. I also tried something closer to Chris's suggestion, try: long except NameError: long = int class C_hash(long): # etc. but (tentatively) opted for something that avoided creating new names at the module level. If it doesn't look too terrible I might stick with it for now (although I am quite tempted to go back to the above). Thanks Skip and Chris. Duncan -- https://mail.python.org/mailman/listinfo/python-list
Re: inheriting from long on Python2 or int on Python3
On Sun, Mar 22, 2020 at 11:31 AM duncan smith wrote: > but (tentatively) opted for something that avoided creating new names at > the module level. If it doesn't look too terrible I might stick with it > for now (although I am quite tempted to go back to the above). Thanks > Skip and Chris. Nah, nothing wrong with creating module-level names for things that would otherwise be builtins. It's like how a __future__ directive applies to the module it's in. Go ahead! It's a nice practical easy way to do things. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: inheriting from long on Python2 or int on Python3
On 3/21/2020 1:19 PM, duncan smith wrote: Hello, I have a class I wrote for Python2 that needs to be made to work on Python3. On Python2 it inherited from long, so it needs to inherit from int on Python3. In general, if you want code to work on both 2 and 3, look into the bi-version packages such as 'six' and 'future' and documents such as https://python-future.org/compatible_idioms.html. If 'long' appears more than once in your code, you might prefer using this at the top. if sys.version_info.major >= 3: long = int This has the plus of indicating that this is a 2 and 3 file, if anyone else reads it. The following works, but I'm not sure it's the cleanest solution. It does not bother me. It's the first time I've wanted / needed to make a parent class conditional on the Python version, and I'm not sure it's even a good idea. I used inheritance because I wanted to perform bitwise operations on instances, but I could probably switch to composition. Just wondering how bad the following really is (in a code smell kind of a away). TIA. import sys class C_hash(int if sys.version_info.major >= 3 else long): def __new__(cls, bits, m, N=1): obj = super(C_hash, cls).__new__(cls, bits) obj._m = m obj._N = N return obj -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Python 3.8.2 on MacOSX Sierra?
I'm trying to compile a framework build of Python 3.8.2 on MacOSX 10.12.6 (Sierra). I'm getting: ./Modules/posixmodule.c:4696:12: warning: 'utimensat' is only available on macOS 10.13 or newer [-Wunguarded-availability-new] return utimensat(dir_fd, path, time, flags); ./Modules/posixmodule.c:4721:12: warning: 'futimens' is only available on macOS 10.13 or newer [-Wunguarded-availability-new] return futimens(fd, time); And later when linking: dyld: lazy symbol binding failed: Symbol not found: _utimensat Referenced from: /Local/Build/Python/Python-3.8.2/Python.framework/Versions/3.8/Python Expected in: /usr/lib/libSystem.B.dylib dyld: Symbol not found: _utimensat Referenced from: /Local/Build/Python/Python-3.8.2/Python.framework/Versions/3.8/Python Expected in: /usr/lib/libSystem.B.dylib make: *** [sharedinstall] Abort trap: 6 Am I out of luck? Is Python 3.8 only intended work on very recent versions of MacOSX? -- Greg -- https://mail.python.org/mailman/listinfo/python-list
