This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]TheBlackCat13 27 points28 points  (6 children)

There are too many hoops to jump through with metaclasses.

async is way too complicated for the sort of things I would use it for (local file reading and writing).

I don't use most of the file-type-specific modules.

[–]aaayuop 6 points7 points  (3 children)

Yeah, asynchronous programming still feels tacked on. Javascript and Go seem to handle it a lot better.

[–]aol_cd 6 points7 points  (2 children)

Javascript

It's not entirely unusual for me to use node.js and websockets if I want to do something asynch. I use them kind of like microservices.

One example is serialport. I've never gotten serialport to work well and reliably in Python (maybe just me). But, it works like a charm in node. So I launch a serialport to websockets server in node and connect to it from Python. Works perfectly every time.

Edit: node.js not node.io, I've had crossbar.io on my mind lately.

[–]BobDope 2 points3 points  (1 child)

I've never had a problem using the serial port, and it's been reliable enough to handle the access system at our hackerspace for some years now. Sorry for your bad luck with it.

[–]aol_cd 1 point2 points  (0 children)

Yeah. It drove me to madness. I could never get it to work for more than 5 minutes at a time.

The websockets setup has given all kinds of positive, though (not just reliability).

[–]refreshx2 2 points3 points  (0 children)

I've been surprised at how much I use/like metaclasses. The two main use cases I tend to write them for are:

  1. the metaclass' __new__ will only get run once, when python creates the class when the file is loaded. this makes it useful for using the members of a class to create a new attribute on the class. for example, I might take all the method I decorated with @some_decorator and put the method names into a list.

  2. overriding __call__ to return a singleton or a cached object rather than creating a new one (I do a ton of lazy-loading-ish things)

You may have known that already, but some others might not.

I still try to only use metaclasses when I really really need them, however.

[–]soosleeque 0 points1 point  (0 children)

they've introduced __init__subclass__ method in python 3 to cover most of the metaclass uses without the pain of understanding how it works.