« first day (4104 days earlier)      last day (844 days later) » 

 
6 hours later…
8:21 AM
Hi guys ...
I have a call to a function timing out and causing the script to exit with error 110
can I work around it and have it continue instead ?
 
8:38 AM
Catch the error it throws?
 
8:48 AM
I will see if I can reproduce it
but surely I can show the code ... as soon I I can turn the rpi back on
 
Function calls usually don't time out. What exactly are you using for the timeout? Some concurrency like asyncio or processes? Is the timeout in some backend code, such as a HTTP request timing out?
 
9:03 AM
pyobex connection is timing out
#!/usr/bin/python

import bluetooth
from PyOBEX.client import Client
import sys
import os.path
import sys
import signal

def cleanup(signum, stack):
  print("Failed")
  for y in failed:
    print(y)
  print("Succeded")
  for x in done:
    print(x)
  sys.exit()

signal.signal(signal.SIGTERM, cleanup)
signal.signal(signal.SIGINT, cleanup)
signal.signal(signal.SIGHUP, cleanup)

done = {}
failed = {}

file_name = sys.argv[1]
if not os.path.isfile(file_name):
  sys.exit("File not fount")


while True:
 
As far as I can tell, the library should just raise a TimeoutError or OSError. As Aran mentioned, you can catch and handle them (ignore, retry, ...) using try: except:
 
9:18 AM
I'm a python newbi ... can you be a little more explicit on how I should go about it ?
 
take a look at tracebacks, are you getting any error messages such as TimeoutError or OSError?
 
I can't reproduce it right now .... I have the pi's SD mounted on the pc ... and here I cannor install the required deps to run iut
but I do remember the error message said timeout
and the error code was 110
 
9:50 AM
cbg
Is there a better name for the function get_item_with_most_occurences(list)?
 
most_common(), or if you want to lean hard into statistics, mode()
 
ah yes thanks mode is what I was having in mind
 
10:29 AM
Ok I got the pi running and I was able to get it to timeout again. this is not exactly the same as last time so maybe there is a whole class of such events:
Traceback (most recent call last):
File "/usr/local/bin/bt_send_to_all", line 60, in <module>
client.connect()
File "/usr/local/lib/python3.9/dist-packages/PyOBEX/client.py", line 155, in connect
self.socket.connect((self.address, self.port))
BlockingIOError: [Errno 115] Operation now in progress
I made a slight change in the code to add a timestamp
but the line number is refering to an imported lib not my code anyway
 
user17681953
10:44 AM
0
Q: Host a simple python socket server in python sockets

Nothingness Is a virtueI have 2 socket scripts (normal ones you found in google assume it as an example) which I want to connect over the internet but I am using usb tethering to have internet in my pc and what I read from google says that sim doesn't allow server on sims is there a workaround on this without relying ...

 
user17681953
It got closed for no reason
 
That's a daunting statement to make.
@NothingnessIsavirtue Please see the room rules. We ask not to advertise new (<48h) questions here.
Also, I doubt that you will get the question reopened by advertising it here in its current state.
 
11:11 AM
@louigi600 I'm not familiar with non-blocking sockets, but reading the documentation of BlockingIOError, I kind of get the impression that that's a bug in pyobex
So either go with the old plan of catching the exception, or report it as a bug
> I have 2 socket scripts (normal ones you found in google assume it as an example)
So that means they're littered with bugs, then?
@NothingnessIsavirtue That whole question consists of three sentences. Three sentences that fill half of my screen. Slow down, breathe, and don't write sentences that are long enough to be a paragraph. It feels like I'm reading your stream of consciousness, not a question.
 
11:41 AM
:53802394 waiting for a bugfix is goning to be long
How do I catch the exception ?
it seems a connect issue so something like
try:
  connect ....
except:
  continue
 
Not sure. Do you want to restart the whole loop or only retry the connect()?
 
sudo
go to next loop iteration
ij skip this address and move to nect address
 
Then yeah, that'll work
 
it probabbly happens if the phone moves out of range while the connection is active
 
I don't think resuming with the next iteration is correct. BlockingIOError means it's still doing something useful.
 
11:45 AM
so usefull it crashes the script
ok what should I be doing ?
maybe I should close current connection before next iteration ?
if the issue is indeed the phone mooving out of range I may also need to do the same for the transmission part
with open(file_name,'rb') as f:
      data = f.read()
 
What is it with people publishing their projects without writing proper documentation? A bit of sample code in the README is the best they can do? Geez
 
It's really hard to say what to do in practice, seeing how the library isn't exactly well documented.
 
On the bright side, I now feel better about my own half-baked documentation. Still a bajillion times better than this.
 
I have another workaround
I could loop the addresses to send to from a bash script and have the pythin script just do the sending
this way if the python script crashes because of timeout the bash part will correctly iterate to the next address
 
The BlockingIOError tells you that the socket is busy and that you should come back later to get results/replies/...; that isn't something that you yourself should do necessarily, rather the library should do so.
 
11:51 AM
@MisterMiyagi the script exits on the error ... not much to come back to later
 
Throwing an exception is not the same thing as exiting.
 
well I get back to a shell prompt
 
Because you didn't catch the exception?
 
call it whatever you want but the script stops running and quits back int the shell that called it
 
The point is that you could easily prevent it from doing that
 
11:53 AM
I don't think it'll be helpful to teach you the basics and background of exceptions.
 
@Aran-Fey maybe ... but what would be the correct way to catch the exception
 
Your shell-loop approach seems sensible, I recommend to use that one.
 
knowing that it is likely that it is because the phone mooved out of range during connection
for me it is ok to try sending next time phone is in range
 
Gotta agree with Miyagi here. I don't have the patience to rehash exceptions for a 3rd time
 
I had a all bash scrpt working ... but it required a real live rerminal because of the way bt-obex works
I want this to run as a service from systemd
so I hadto scrap that idea
this is why I went to python looking for a way to send files without the necessity to have a real terminal
it was dbus complaining aboun not having a display to be precise
no it seems stupid to have a command line only tool like bt-obex look for a display... but what the hell the world is going nuts ... I don't want to go nuts after it
 
12:02 PM
It's perfectly possible to do this in Python, it's just not clear what you have, what you know, and what the library provides. Teaching you a broad picture on all of that isn't going to fit into the time we have.
If you just want to avoid the shell, you can also use subprocess, concurrent.futures or multprocessing to do the "one process per address" dance.
 
12:31 PM
I posted the code earlier
not so many lines ... should be representative of what I want
small portion of it is to handle prpducing some log of what was done and what failed when the process gets terminated
the rest should just
1)scan bt devices
2)for those who are obex push capable send a file
3)go back to step 1

lope there untill terminated externally
second time I ever wrote something in python so forgive me if it makes no sense
 
That's all fine and good. The problem is that non-blocking sockets are quite a beast, so remotely telling you how to use a tool you are not at all familiar with (exceptions) isn't going to be productive.
If you can get it working with a shell loop and multiple Python processes that you can just let fail, by all means do so.
A different topic: Has anyone here used PyPy + Asyncio? I'm seeing abysmal performance in unittests and am wondering whether it's just that the JIT hasn't warmed up.
"Abysmal" means taking 4x as long when having 2048 tasks wait on futures and triggering them by setting their results. (0.21s vs. 0.04s)
 
 
2 hours later…
2:53 PM
Wuhu I used my standing desk for the first time today gotta say it's quite nice, but after 2h I've had enough. Is there a good ergonomic advice on what balance between sitting and standing one should have during the day?
 
3:05 PM
My instincts say "follow your instincts"
 
If you haven’t used one before, it’s going to take a while until you get used to it. When we got one at home my feet would hurt after the first week…
 
3:31 PM
use a sit-stand desk. The desk moves up/down so you can sit when you need to
 
:53802872 with a bit of research and help from a friend I came up with this (just the part where the error can happen)
    try:
      client = Client(services[0]["host"],services[0]["port"])
      with client.connect():
        #client.put('test.txt', 'HelloWorld!')
        with open(file_name,'rb') as f:
          data = f.read()
          if client.put(file_name,data):
            done[services[0]["host"]] = True
          else:
            failed[services[0]["host"]] = True
    except Exception e:
 
3:49 PM
@Hakaishin If you don't have a good anti-fatigue mat, get one now
 
Is it like a carpet?
 
think memory foam, but for your feet
 
Good call. Grocery store cashiers and bartenders use anti-fatigue mats. Take a look at this: uline.ca/BL_1751/Anti-Fatigue-Mats
 
there are a couple of styles, like ergodriven.com/products/topo?variant=31072677331062 is one of the popular "different" styles
there was one that I"m trying to find...
 
Is it much different than a carpet? We simply got a small 5mm carpet
maybe 5-10mm
 
3:56 PM
can't seem to find it, but the one I saw actually had foam rocks & branches on it
the basic gist is that the human body is optimized for uneven terrain
standing on an even surface for several hours is not great
 
A carpet is too rigid. The material of these mats is much more forgiving, which is more comfortable on your feet. There was a time I used to stand barefoot at my desk, on a platform of fake grass
 
in terms of things concrete < wood < carpet < foam mat
that is, the carpet is better than whatever the heck you have on your floor, but a foam mat is way better than that
 
foam rocks sounds really good. I wish I'd tried that
 
I was just looking and a lot of ones available now have like... rolly balls in the middle that you can use to give your self a foot massage
I don't have a standing desk anymore, but when I did, the foam mat was essential for a full day
I'd also recommend the sit/stand deal - sometimes your body needs to stand and sometimes it needs to sit
 
That must have been why liked the earth/grass idea
I also highly recommend a foam roller for your back
 
4:00 PM
Hmm weird, amazon is banned in switzerland and our version of it doesn't have it
 
if you can't toggle between the two, having a tall chair is +1
 
oh yes! Bar chairs are awesome for this. They even have a height-adjusting lever
 
Amazon is banned in Switzerland? :O
 
bad working conditions and such and a bit of domestic protection. I'd say it's a 60/40 split
 
Everything I'm finding suggests that it was due to changes in your VAT system that made Amazon back away, rather than an actual ban?
 
4:09 PM
well then I've been talking bollocks :D The other two reasons are just what came to my mind :P
 
<cough> yam </cough> :)
 
is bollocks a curse word? As a non native speaker it can be hard to tell sometimes how "strong" a word is
 
Yep
 
In my mind it is something which an older dad in a sitcom would use
hmm, I'm open to learn replacement words. talking yam seems a bit childish. I guess I was talking nonsense
 
@Hakaishin On a par with certain words for excrement, at least in the UK
 
4:11 PM
there is something about the sound of *** used above which just sounds fitting
I must have picked id up from David and Mitchel, man their shows are great
 
cbg everyone
 
You mean Mitchell and Webb?
 
right :D
 
4:27 PM
David Mitchell is far too great a man to split him in half :P
 
David Mitchell is actually one of my favourite comedians... especially when he gets onto a rant :p
I've been told my sense of humour reminds people of Mitchell.... I'm not sure if that's a compliment for anyone but... oh well.
 
4:46 PM
I'd take it as a compliment
 
My first non technical comment in about 2 years: # This is stupid and doesn't make sense, but politics demands it
 
5:11 PM
Love it when I get an email with the subject "PASTE PROMO 1 SUBJECT LINE HERE" - I know it was meant just for me
 
5:25 PM
If you're getting Number 1, you should feel really privileged. They don't dish that promo out to just anyone
 
What's the reason why dundermethods defined on instances don't work? I always assumed it has something to do with metaclasses, but I don't actually know for sure
class Demo:
    __str__ = lambda self: 'class'

demo = Demo()
demo.__str__ = lambda self: 'instance'

print(str(demo))  # Output: class
 
Try the same with __slots__ = "__str__",
It's looking specifically for a descriptor up the "method" like any descriptor.
 
Kinda? Yes, some descriptors can take priority over instance attributes. But if no descriptor is present, then it'll just use the instance attribute. Dundermethods don't work that way
class Demo:
    pass

demo = Demo()
demo.__str__ = lambda self: 'instance'

print(str(demo))  # Output: <__main__.Demo object at 0x00000217F074F100>
 
5:42 PM
*mumble mumble* data descriptor *mumble mumble*
 
Anyway, it doesn't answer the "why"
 
I'd say the formal reason is that it's looking for a method, not a callable attribute.
 
So it's just a happy coincidence that this behavior makes metaclasses more sane? That wasn't the goal?
 
Does it make metaclasses more sane?
I always get the mind bendies when thinking about type.__dict__
type.__call__ also is kinda weird to reason about for me.
 
Imagine if dunders were looked up on instances:
class Person:
    def __init__(self, name):
        self.name = name

    def __str__(self):
        return self.name

duncan = Person('Duncan')
print(duncan)  # Duncan
print(Person)  # AttributeError: type object 'Person' has no attribute 'name'
I guess I didn't need to go as far as metaclasses. Evidently it also makes regular classes more sane
But you would need a metaclass to "fix" this
...which, in turn, would/might leave you with a "broken" metaclass
So the two sensible solutions I can think of are:
1) Don't look up dunders on instances
2) Do look up dunders on instances, except if it's an instance of `type`
And I'm a bit surprised it turned out to be solution 1 and not solution 2
 
6:19 PM
I honestly don't see a point with "look up dunders on instances". dunders are methods and methods don't live on instances.
It's a bit weird that Python's . operator cannot accurately express the dunder lookup, admittedly.
 
Hmm, I can see where you're coming from. I called it a "coincidence" earlier, but in a way it's just... the right way to do it
 
@MisterMiyagi so what are non-dunder methods?
Or is your point that monkeypatching a non-dunder method on an instance will make it not-a-method?
 
@AndrasDeak methods that don't have dunder names
@AndrasDeak Yeah. A "patched method" just a callable attribute that shadows the method.
 
Hmm, yeah, I just checked and it doesn't even get self passed. I was sure it did.
that makes a lot of sense
 
It makes sense if you look at this way: The object's namespace holds the state object, while the class's namespace holds the functionality of the object. So getting dunders from the class is just the right thing to do. Although then the weird thing is that there's no easy way to correctly call a method (because obj.method() might reference an instance attribute instead of the method you wanted)
 
6:29 PM
I've had quite some battles with the latter to correctly implement aiter(obj) and friends. Just obj.__aiter__() technically is wrong.
 
Is that what your slot_get function does? If so, it's not completely correct
 
It's missing inheritance, does it?
I've just realised that the only place I'm using it is wrong to begin with.
Context manager calls don't use special method lookup. D:
 
Wait, really? But they should... right?
The problem isn't inheritance, getting the dunder from a parent class works just fine with your getattr. The problem is that you could accidentally get it from the metaclass instead of the class
class Meta(type):
    def __int__(self): return 5

class Class(metaclass=Meta): pass

obj = Class()

print(slot_get(obj, '__int__')())  # 5
print(int(obj))  # TypeError
I have a library that can do this kind of thing, but just yesterday I realized it's also not completely correct... that's why I was asking about __get__
 
@Aran-Fey I'm not 100% sure, TBH. There are not C slots for __enter__ and friends at least.
 
I can send you my code if you want, or publish a new version with the fix
 
6:42 PM
I'll probably nuke the helper, but thanks for the offer.
 
FWIW, I've seen plenty of incorrect dunder-calls in the stdlib
 
I'm somewhat paranoid about runtime cost.
 
Yeah, looping through 2 MROs is a bit...
 
I can ping you when I finally get around to my next try with Cython. :P
 
7:44 PM
Every time I write with youtube_dl.YoutubeDL() as ydl: my brain gives me a mental image of a guy yodelling
 
Are you sure that line of code has anything to do with that? :P
 
How strange; that's twice that yodelling has come up today
 
A study I've involuntarily participated in for the last 3 years has concluded that yes, it is indeed related to that line (and similar ones)
 
"Person X (one of our account managers) has recently taken up a course in yodelling. Turns out it was over-subscribed so at the registration they were asked to form an orderly, orderly, orderly queue". It's customary for someone to tell a terrible joke at the start of our meetings; that was today's
 
7:50 PM
Yeah, what he said
 
You're welcome
 
 
2 hours later…
10:04 PM
On a conceptual level (i.e. I'm not asking for specifics): Can Java and Python share an object in memory (it can be as simple-an-object as one likes to prove the point)?
I thought the JVM would basically ringfence everything in the first place. It seems like a hack that some other process could somehow access that memory
 
10:44 PM
@roganjosh Sure, Java & Python have their own way of doing objects & organising memory, so they can't just share any kind of object. OTOH, both languages support memory-mapped files. In Python, we have MemoryView.I know almost nothing about Java, so I can't give details on that front.
Another option is to use Ramdisk files, as mentioned in en.wikipedia.org/wiki/Shared_memory It's easy enough to do this sort of thing when only one process is writing the data to the shared memory space, but it gets tricky if multiple processes want to write to the same space. Using files to communicate is conceptually cleaner & less confusing. ;)
 

« first day (4104 days earlier)      last day (844 days later) »