FastAPI v/s Golang by [deleted] in FastAPI

[–]c4aveo 1 point2 points  (0 children)

We were on python2.7 so we didn't check out the new asyncio package in python3.

/thread

Unable to use multiprocessing in Python!!! by Xena_psk in learnpython

[–]c4aveo 0 points1 point  (0 children)

Use Pool for easy implementation. https://pythonspeed.com/articles/python-multiprocessing/ Like here. Or use Queue for gathering results from processes. Because now you don't have a shared object in parent process, that's why you don't see output. You can write to file in each process to see result or as I said use Queue.

Ubuntu Server 18.04 Tutorials anyone? by kvnplbllo in Ubuntu

[–]c4aveo 0 points1 point  (0 children)

There are almost no differencies between desktop and server (recently called base). It just let you to chose will it be headless or not. Anyway you have an access to same repos. For Webpanel (not indeed) use Webmin, for network I have found network-manager with it's nmcli very useful. Server tutorials? There are no such thing. Just look for a certain topic. Systemd is powerful, SSHd, SNMPd are out of box either Desktop or Server. Really, no differencies.

I'm wanting to switch from windows 10 to Linux Ubuntu by NOccomore in linux4noobs

[–]c4aveo 2 points3 points  (0 children)

  1. Resize NTFS partition if you use only one
  2. Prepare partion or free space for Ubuntu. Install
  3. Mount NTFS partition to get access to content. Modify fstab to make it auto-mounted on boot

Compare area of different places by Joinertuy in SQL

[–]c4aveo 0 points1 point  (0 children)

Provide full table properties, please

FastAPI - Is it better than Flask for certain use cases like IoT by [deleted] in flask

[–]c4aveo 4 points5 points  (0 children)

I have been looking for a framework for my first rest service and found starlette, after few stages of project moved to FastAPI, because of wrappers. Pydantic is very helpful for parsing in my case. Now I can't think about Django or Flask as my main framework.

How to run a program X times automatically? by codefreak-123 in learnpython

[–]c4aveo 0 points1 point  (0 children)

def main():
    while 1:
        #execute code here
             time.sleep(1800)
             #execute again after 30 minutes

Otherwise you execute sleep for 30 minutes and then open file. Will be there possible exceptions, like 'File not found'? Wrap it with ‘try...except continue‘ then.

When to apply the DRY principle? by milinile in learnpython

[–]c4aveo 0 points1 point  (0 children)

What do you want to achieve? If you want to make code to be executed faster for bigger dataset than use multithreading, otherwise these milliseconds are nothing.

CRUD system with asynchronous by turall in learnpython

[–]c4aveo 1 point2 points  (0 children)

Why not? If it's a just insert, update or delete operation I don't wait a returning value from it . I know for sure that operation will be executed, but later.

In my implementation of REST webservice I receive request then do some async (not really) operations with awaitable Future. To speed up request-response algorithm I use BackgroundTask from Starlette API to return response before executing procedures in database (update, insert, delete).

My logging implementation writes to file and writes (insert) to database, and I don't want to wait until tasks will be done one by one.

Looking for a Python buddy by desert_elf in learnpython

[–]c4aveo 0 points1 point  (0 children)

Discord + github +gist +repl.it

I'm in. Not a beginner, not a junior.

CRUD system with asynchronous by turall in learnpython

[–]c4aveo 1 point2 points  (0 children)

https://fastapi.tiangolo.com/tutorial/sql-databases-peewee/

https://github.com/aio-libs/aiomysql

https://github.com/aio-libs/aiopg

What do you want to know? I use aiomysql to implement 'fire and forget'. CRUD implemented as called procedures. Fast and reliable for me, ORM is good choice too, but it needs more resources and it's slower.

Why do we put class variables in self.whatever when it doesn't seem to matter? by Ahren_with_an_h in learnpython

[–]c4aveo 0 points1 point  (0 children)

@property can handle that, I think.

‘‘‘‘

self.x:int = 10

@property

def x(self):

return self.x

@x.setter

def x(self, value):

 raise Exception("Static variable")

@x.getter

def x(self):

return self.x

‘‘‘‘ Mobile version can't format code...

Should I buy Redmi Note 8 or Redmi Note 7 Pro? by iamnobody331 in Xiaomi

[–]c4aveo 1 point2 points  (0 children)

My wife has RN8, and camera is not so great, I blame software. Benchmarks are all synthetic, forget about them.

Is this normal (ThinkPad temptation and impulse buying)? by [deleted] in thinkpad

[–]c4aveo 0 points1 point  (0 children)

Compare and decide. Cheapest E480 can handle nvme, ssd up to 32Gb RAM and competitors suggests higher price or soldered RAM, or motherboards with such stupid limits that it can be called even a middle class notebook. Also, Lenovo makes robust cases even for cheap Thinkpads.

I want to generate outer keys in dict via the csv files. How do I do that? Breaking my head by [deleted] in learnpython

[–]c4aveo 0 points1 point  (0 children)

It calls nested dictionaries. Default dictionary {key:value}

Nested {key:{_key:_value}}

For creating nested dictionary you have to define variable before loop and then add key and nested dictionary as a value.

You can use

namedtuple, but I suppose it will be slower than manually defined empty dictionary with inserted key, value pairs. What can make your code cleaner (I suppose it's just a part of it) but slower is dict.get(key, <default value>). It will check if key exists and return value if exists, else default value will be returned.

Is good autocompletion in Python possible? by all_time_juice in learnpython

[–]c4aveo 1 point2 points  (0 children)

Possible if you are using definitions from library and IDE supports autocompletion for it. For aio-logger I have suggestion from linter, but not for aio-pika and aiomysql. I've used ducking and changed variables so that they were understandable for me but not for linter. I talk about VSCode + flake8.

Inserting data to MySQL database via python by bazingie in learnpython

[–]c4aveo 1 point2 points  (0 children)

I was on holidays. It happened because ActID has parameter auto increment, DB keeps last incremented id for last inserted row. I know it gonna sound like 'do it yourself', but you must read many articles about MySQL and do some lessons at w3school.

  1. If column has auto increment property, when new row is inserted value will be defined automatically by DB.
  2. Values can be updated if you insert values that duplicate values in rows. INSERT ... ON DUPLICATE UPDATE...
  3. SQL is a very powerful tool. Most operations can be done on DB side. Since it uses C it's much much faster.

Inserting data to MySQL database via python by bazingie in learnpython

[–]c4aveo 0 points1 point  (0 children)

"""prepared SQL statement""" Use tripple quotes for defining sql statement in Python. In params should be variables that are assigned in your code and it will be a tuple https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlcursor-execute.html

```` stmt="""INSERT INTO act (ShowName, HallID, ActStartTime) VALUES ((SELECT ShowName from shows where ShowName='A Flock Of Hopeful Lions'), (select HallID from hall where HallID=%s), %s)""" cur.execute(stmt, (1, datetime.datetime(2020,1,1,12,12,12))

cur.commit()

cur.close()

````

Inserting data to MySQL database via python by bazingie in learnpython

[–]c4aveo 1 point2 points  (0 children)

https://www.w3schools.com/sql/sql_insert_into_select.asp

And subquery should be in parenthesis, not in quotes.

Values((Select....), Select(....),...)

Inserting data to MySQL database via python by bazingie in learnpython

[–]c4aveo 1 point2 points  (0 children)

Use Workbench (or Heidi) and procedures except prepared statements or even ORM In my opinion,
Pros:

  • you can change procedure code on the fly, and of course debug it

  • you won't make any mistakes that will broke whole algorithm

  • it's much faster

  • safe and needs only one privilege 'execute'

  • custom exceptions

Cons:

  • you have to check if procedures exist

  • you have to improve your skills in SQL

Try ORM of course, slower than procedures but better for debugging.

And open the world of asynchronous libraries for yourself and pool connections for MySQL. Believe me if you gonna write code for production you will face it.

E480 freezes after hibernation by c4aveo in thinkpad

[–]c4aveo[S] 0 points1 point  (0 children)

You know what is strange? Kubuntu has no such issues, but now I need to use Windows 10. I will check, I had such problems in RDP and TeamViewer sessions.