Re: Using a background thread with asyncio/futures with flask
Sorry, must have missed that :-/ Lars Liedtke Lead Developer [Tel.] +49 721 98993- [Fax] +49 721 98993- [E-Mail]l...@solute.de<mailto:l...@solute.de> solute GmbH Zeppelinstraße 15 76185 Karlsruhe Germany [Marken] Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten Webseite | www.solute.de <http://www.solute.de/> Sitz | Registered Office: Karlsruhe Registergericht | Register Court: Amtsgericht Mannheim Registernummer | Register No.: HRB 748044 USt-ID | VAT ID: DE234663798 Informationen zum Datenschutz | Information about privacy policy https://www.solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php Am 22.03.24 um 08:58 schrieb Chris Angelico via Python-list: On Fri, 22 Mar 2024 at 18:35, Lars Liedtke via Python-list <mailto:python-list@python.org> wrote: Hey, As far as I know (might be old news) flask does not support asyncio. You would have to use a different framework, like e.g. FastAPI or similar. Maybe someone has already written "flask with asyncio" but I don't know about that. Did you try searching their documentation? https://flask.palletsprojects.com/en/3.0.x/async-await/ ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Using a background thread with asyncio/futures with flask
Hey, As far as I know (might be old news) flask does not support asyncio. You would have to use a different framework, like e.g. FastAPI or similar. Maybe someone has already written "flask with asyncio" but I don't know about that. Cheers Lars Lars Liedtke Lead Developer [Tel.] +49 721 98993- [Fax] +49 721 98993- [E-Mail]l...@solute.de<mailto:l...@solute.de> solute GmbH Zeppelinstraße 15 76185 Karlsruhe Germany [Marken] Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten Webseite | www.solute.de <http://www.solute.de/> Sitz | Registered Office: Karlsruhe Registergericht | Register Court: Amtsgericht Mannheim Registernummer | Register No.: HRB 748044 USt-ID | VAT ID: DE234663798 Informationen zum Datenschutz | Information about privacy policy https://www.solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php Am 20.03.24 um 09:22 schrieb Thomas Nyberg via Python-list: Hello, I have a simple (and not working) example of what I'm trying to do. This is a simplified version of what I'm trying to achieve (obviously the background workers and finalizer functions will do more later): `app.py` ``` import asyncio import threading import time from queue import Queue from flask import Flask in_queue = Queue() out_queue = Queue() def worker(): print("worker started running") while True: future = in_queue.get() print(f"worker got future: {future}") time.sleep(5) print("worker sleeped") out_queue.put(future) def finalizer(): print("finalizer started running") while True: future = out_queue.get() print(f"finalizer got future: {future}") future.set_result("completed") print("finalizer set result") threading.Thread(target=worker, daemon=True).start() threading.Thread(target=finalizer, daemon=True).start() app = Flask(__name__) @app.route("/") async def root(): future = asyncio.get_event_loop().create_future() in_queue.put(future) print(f"root put future: {future}") result = await future return result if __name__ == "__main__": app.run() ``` If I start up that server, and execute `curl http://localhost:5000`, it prints out the following in the server before hanging: ``` $ python3 app.py worker started running finalizer started running * Serving Flask app 'app' * Debug mode: off WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. * Running on http://127.0.0.1:5000 Press CTRL+C to quit root put future: worker got future: worker sleeped finalizer got future: finalizer set result ``` Judging by what's printing out, the `final result = await future` doesn't seem to be happy here. Maybe someone sees something obvious I'm doing wrong here? I presume I'm mixing threads and asyncio in a way I shouldn't be. Here's some system information (just freshly installed with pip3 install flask[async] in a virtual environment for python version 3.11.2): ``` $ uname -a Linux x1carbon 6.1.0-18-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.76-1 (2024-02-01) x86_64 GNU/Linux $ python3 -V Python 3.11.2 $ pip3 freeze asgiref==3.7.2 blinker==1.7.0 click==8.1.7 Flask==3.0.2 itsdangerous==2.1.2 Jinja2==3.1.3 MarkupSafe==2.1.5 Werkzeug==3.0.1 ``` Thanks for any help! Cheers, Thomas -- https://mail.python.org/mailman/listinfo/python-list
Re: pip-sync
Did maybe pip-sync create the venv with --system-site-packages (at least that's the commandline option for pip) I only saw behaviour like this so far, when my venv was with --system-site-packages and a package was installed by the system. Sorry for the first mess. Cheers Lars Lars Liedtke Senior Software Developer [Tel.] [Fax] +49 721 98993- [E-Mail]l...@solute.de<mailto:l...@solute.de> solute gmbh Zeppelinstraße 15 76185 Karlsruhe Germany [Logo Solute] Marken der solute gmbh | brands of solute gmbh [Marken] Triff uns auf der DMEXCO am 20. und 21. September in Köln und sichere dir die Chance auf eine brandneue Apple-Watch bei unserer Live-Auslosung! Vereinbare hier einen Termin mit uns: https://outlook.office365.com/owa/calendar/solutedme...@o365.solute.de/bookings/ [dmexco Banner]<https://outlook.office365.com/owa/calendar/solutedme...@o365.solute.de/bookings/> Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten Webseite | www.solute.de <http://www.solute.de/> Sitz | Registered Office: Karlsruhe Registergericht | Register Court: Amtsgericht Mannheim Registernummer | Register No.: HRB 110579 USt-ID | VAT ID: DE234663798 Informationen zum Datenschutz | Information about privacy policy https://www.solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php Am 21.07.23 um 20:08 schrieb Larry Martell via Python-list: I am trying to set up and maintain a venv with pip-sync. On my bare metal I have the apparmor python package installed, but it is not installed in my venv and it's not in my requirements file. When I run pip-sync I get: Found existing installation: apparmor 2.13.3 ERROR: Cannot uninstall 'apparmor'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall. Since it's not installed in the venv why does it want to uninstall it? -- https://mail.python.org/mailman/listinfo/python-list
Re: pip-sync
This email contains a secure message that can be read by opening the attachment. Lars Liedtke Senior Software Developer [Tel.] [Fax] +49 721 98993- [E-Mail]l...@solute.de<mailto:l...@solute.de> solute gmbh Zeppelinstraße 15 76185 Karlsruhe Germany [Logo Solute] Marken der solute gmbh | brands of solute gmbh [Marken] Triff uns auf der DMEXCO am 20. und 21. September in Köln und sichere dir die Chance auf eine brandneue Apple-Watch bei unserer Live-Auslosung! Vereinbare hier einen Termin mit uns: https://outlook.office365.com/owa/calendar/solutedme...@o365.solute.de/bookings/ [dmexco Banner]<https://outlook.office365.com/owa/calendar/solutedme...@o365.solute.de/bookings/> Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten Webseite | www.solute.de <http://www.solute.de/> Sitz | Registered Office: Karlsruhe Registergericht | Register Court: Amtsgericht Mannheim Registernummer | Register No.: HRB 110579 USt-ID | VAT ID: DE234663798 Informationen zum Datenschutz | Information about privacy policy https://www.solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php --- Begin Message --- Did maybe pip-sync create the venv with --system-site-packages (at least that's the commandline option for pip) I only saw behaviour like this so far, when my venv was with --system-site-packages and a package was installed by the system. Cheers Lars Am 21.07.23 um 20:08 schrieb Larry Martell via Python-list: I am trying to set up and maintain a venv with pip-sync. On my bare metal I have the apparmor python package installed, but it is not installed in my venv and it's not in my requirements file. When I run pip-sync I get: Found existing installation: apparmor 2.13.3 ERROR: Cannot uninstall 'apparmor'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall. Since it's not installed in the venv why does it want to uninstall it? OpenPGP_signature Description: OpenPGP digital signature --- End Message --- -- https://mail.python.org/mailman/listinfo/python-list
Re: Best practices for using super()
Hey, When you have multiple inheritance and you e.g. want to explicitely call __init__ of one of the classes inherited from, that is not the first in the list of classes to inherit from. Cheers, Lars Lars Liedtke Senior Software Developer [Tel.] +49 721 98993- [Fax] +49 721 98993- [E-Mail]l...@solute.de<mailto:l...@solute.de> solute GmbH Zeppelinstraße 15 76185 Karlsruhe Germany [Logo Solute] Marken der solute GmbH | brands of solute GmbH [Marken] [Advertising Partner] Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten Webseite | www.solute.de <http://www.solute.de/> Sitz | Registered Office: Karlsruhe Registergericht | Register Court: Amtsgericht Mannheim Registernummer | Register No.: HRB 110579 USt-ID | VAT ID: DE234663798 Informationen zum Datenschutz | Information about privacy policy https://www.solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php Am 04.07.23 um 14:20 schrieb Peter Slížik via Python-list: As a follow-up to my yesterday's question - are there any recommendations on the usage of super()? It's clear that super() can be used to invoke parent's: - instance methods - static methods - constants ("static" attributes in the parent class, e.g. super().NUMBER). This all works, but are there situations in which calling them explicitly using a parent class name is preferred? Best regards, Peter -- https://mail.python.org/mailman/listinfo/python-list
Re: for a 'good python'
Lars Liedtke Software Entwickler [Tel.] +49 721 98993- [Fax] +49 721 98993- [E-Mail]l...@solute.de<mailto:l...@solute.de> solute GmbH Zeppelinstraße 15 76185 Karlsruhe Germany [Logo Solute] Marken der solute GmbH | brands of solute GmbH [Marken] [Advertising Partner] Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten Webseite | www.solute.de <http://www.solute.de/> Sitz | Registered Office: Karlsruhe Registergericht | Register Court: Amtsgericht Mannheim Registernummer | Register No.: HRB 110579 USt-ID | VAT ID: DE234663798 Informationen zum Datenschutz | Information about privacy policy https://www.solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php Am 13.04.23 um 00:21 schrieb jak: Barry ha scritto: On 12 Apr 2023, at 18:10, jak <mailto:nos...@please.ty> wrote: Hi everyone, some time ago I wrote a class to determine if an ipv4 address belonged to a subnet. Seldom using python I'm pretty sure it's not written in 'good python' nor too portable. Could you give me some advice to make it better? class calcip: def __init__(self, psubnet: str): ssubnet, scidr = psubnet.replace(' ', '').split('/') subnet = int.from_bytes(tuple( map(lambda n: (int(n)), ssubnet.split('.'))), 'big') cidr = int(scidr) mask = ((2 ** cidr) - 1) << (32 - cidr) self.__network = subnet & mask self.__wildcard = ~mask & 0x self.__broadcast = (subnet | self.__wildcard) & 0x self.__tsubnet = tuple(subnet.to_bytes(4, 'big')) self.__tnetwork = tuple(self.__network.to_bytes(4, 'big')) self.__tbroadcast = tuple(self.__broadcast.to_bytes(4, 'big')) self.__tmask = tuple(mask.to_bytes(4, 'big')) self.__twildcard = tuple(self.__wildcard.to_bytes(4, 'big')) self.__host_min = tuple((self.__network + 1).to_bytes(4, 'big')) self.__host_max = tuple((self.__broadcast - 1).to_bytes(4, 'big')) @staticmethod def __to_str(val: tuple): return '.'.join(str(v) for v in val) @property def subnet(self): return self.__to_str(self.__tsubnet) @property def network(self): return self.__to_str(self.__tnetwork) @property def broadcast(self): return self.__to_str(self.__tbroadcast) @property def mask(self): return self.__to_str(self.__tmask) @property def wildcard(self): return self.__to_str(self.__twildcard) @property def host_min(self): return self.__to_str(self.__host_min) @property def host_max(self): return self.__to_str(self.__host_max) @property def hosts_num(self): return self.__wildcard - 1 @property def net_class(self): tst = (self.__tnetwork[0] & 0xf0) >> 4 if (tst & 0x8) == 0: clx = 'A' elif (tst & 0xc) == 0x8: clx = 'B' elif (tst & 0xe) == 0xc: clx = 'C' elif (tst & 0xf) == 0xe: clx = 'D' elif (tst & 0xf) == 0xf: clx = 'E' return clx def __contains__(self, item): ret = True row_hdr = None try: row_hdr = int.from_bytes(tuple(map(lambda n: (int(n)), item.split('.'))), 'big') except: ret = False if ret: if not self.__network < row_hdr < self.__broadcast: ret = False return ret def main(): sn = calcip('10.0.0.0/26') print(f"subnet: {sn.subnet}") print(f"network: {sn.network}") print(f"broadcast: {sn.broadcast}") print(f"mask: {sn.mask}") print(f"wildcard: {sn.wildcard}") print(f"host_min: {sn.host_min}") print(f"host_max: {sn.host_max}") print(f"Avaible hosts: {sn.hosts_num}") print(f"Class: {sn.net_class}") tst_hdr = '10.0.0.31' is_not = 'is ' if not tst_hdr in sn: is_not = 'is NOT ' print("hdr %s %sin range %s - %s" % (tst_hdr, is_not, sn.host_min, sn.host_max)) if __name__ == '__main__': main() There is this https://docs.python.org/3/howto/ipaddress.html if you just want a solution. Or are you after code review feedback? Barry -- https://mail.python.org/mailman/listinfo/python-list Thank you too. I had seen this library but I always try not to use libraries outside the standard ones. Now I don't remember why I was convinced that this wasn't part of it, perhaps because it was like that at the time or because I got confused. Only now I realized that it is not necessary to install it. Now I'm considering whether to use 'ipaddress' or 'socket'. What is certain is that this one you have suggested is really comfortable. Thanks again for the report. Unless I am not mistakes, ipadress is "standard" because it is in the standard library -- https://mail.python.org/mailman/listinfo/python-list
Re: 转发: How to exit program with custom code and custom message?
I totally understand your reasoning here, but in some way it follows the unix philosophy: Do only one thing, but do that good. And exiting is something different from printing to STDOUT or STDERR. Yes sometimes you want to print something before exiting. But then you should do that explicitly and to the output you want and not implicitly rely on adfdtitional parameters of exit. Yes, not all functions work this way. But that does not mean they shouln't ;-) Cheers Lars On 13.03.23 11:18, scruel tao wrote: Chris: It doesn't actually take a list of arguments; the square brackets indicate that arg is optional here. Oh, I see, it seems that I mistunderstood the document. but for anything more complicated, just print and then exit. It's worth noting, by the way, that sys.exit("error message") will print that to STDERR, not to STDOUT, which mean that the equivalent is: Yes, I know, but don’t you think if `sys.exit` can take more parameters and have a default output channel selection strategy will be better? Thanks. Lars Liedtke Software Entwickler [Tel.] +49 721 98993- [Fax] +49 721 98993- [E-Mail]l...@solute.de<mailto:l...@solute.de> solute GmbH Zeppelinstraße 15 76185 Karlsruhe Germany [Logo Solute] Marken der solute GmbH | brands of solute GmbH [Marken] [Advertising Partner] Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten Webseite | www.solute.de <http://www.solute.de/> Sitz | Registered Office: Karlsruhe Registergericht | Register Court: Amtsgericht Mannheim Registernummer | Register No.: HRB 110579 USt-ID | VAT ID: DE234663798 Informationen zum Datenschutz | Information about privacy policy https://www.solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php -- https://mail.python.org/mailman/listinfo/python-list
Re: Fast lookup of bulky "table"
Hey, before you start optimizing. I would suggest, that you measure response times and query times, data search times and so on. In order to save time, you have to know where you "loose" time. Does your service really have to load the whole table at once? Yes that might lead to quicker response times on requests, but databases are often very good with caching themselves, so that the first request might be slower than following requests, with similar parameters. Do you use a database, or are you reading from a file? Are you maybe looping through your whole dataset on every request? Instead of asking for the specific data? Before you start introducing a cache and its added complexity, do you really need that cache? You are talking about saving microseconds, that sounds a bit as if you might be “overdoing” it. How many requests will you have in the future? At least in which magnitude and how quick do they have to be? You write about 1-4 seconds on your laptop. But that does not really tell you that much, because most probably the service will run on a server. I am not saying that you should get a server or a cloud-instance to test against, but to talk with your architect about that. I totally understand your impulse to appear as good as can be, but you have to know where you really need to debug and optimize. It will not be advantageous for you, if you start to optimize for optimizing's sake. Additionally if you service is a PoC, optimizing now might be not the first thing you have to worry about, but about that you made everything as simple and readable as possible and that you do not spend too much time for just showing how it could work. But of course, I do not know the tasks given to you and the expectations you have to fulfil. All I am trying to say is to reconsider where you really could improve and how far you have to improve. Lars Liedtke Software Entwickler [Tel.] +49 721 98993- [Fax] +49 721 98993- [E-Mail]l...@solute.de<mailto:l...@solute.de> solute GmbH Zeppelinstraße 15 76185 Karlsruhe Germany [Logo Solute] Marken der solute GmbH | brands of solute GmbH [Marken] [Advertising Partner] Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten Webseite | www.solute.de <http://www.solute.de/> Sitz | Registered Office: Karlsruhe Registergericht | Register Court: Amtsgericht Mannheim Registernummer | Register No.: HRB 110579 USt-ID | VAT ID: DE234663798 Informationen zum Datenschutz | Information about privacy policy https://www.solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php Am 15.01.23 um 05:26 schrieb Dino: Hello, I have built a PoC service in Python Flask for my work, and - now that the point is made - I need to make it a little more performant (to be honest, chances are that someone else will pick up from where I left off, and implement the same service from scratch in a different language (GoLang? .Net? Java?) but I am digressing). Anyway, my Flask service initializes by loading a big "table" of 100k rows and 40 columns or so (memory footprint: order of 300 Mb) and then accepts queries through a REST endpoint. Columns are strings, enums, and numbers. Once initialized, the table is read only. The endpoint will parse the query and match it against column values (equality, inequality, greater than, etc.) Finally, it will return a (JSON) list of all rows that satisfy all conditions in the query. As you can imagine, this is not very performant in its current form, but performance was not the point of the PoC - at least initially. Before I deliver the PoC to a more experienced software architect who will look at my code, though, I wouldn't mind to look a bit less lame and do something about performance in my own code first, possibly by bringing the average time for queries down from where it is now (order of 1 to 4 seconds per query on my laptop) to 1 or 2 milliseconds on average). To be honest, I was already able to bring the time down to a handful of microseconds thanks to a rudimentary cache that will associate the "signature" of a query to its result, and serve it the next time the same query is received, but this may not be good enough: 1) queries might be many and very different from one another each time, AND 2) I am not sure the server will have a ton of RAM if/when this thing - or whatever is derived from it - is placed into production. How can I make my queries generally more performant, ideally also in case of a new query? Here's what I have been considering: 1. making my cache more "modular", i.e. cache the result of certain (wide) queries. When a complex query comes in, I may be able to restrict my search to a subset of the rows (as determined by a previously cached partial query). This should keep the memory footprint under control. 2. Load my data into a numpy.array and use numpy.array operations to slice and dice m
Re: How to enter escape character in a positional string argument from the command line?
Or you could have "native" bash ($SHELL) with WSL. But I assume not everyone is using it. Cheers Lars Lars Liedtke Software Entwickler [Tel.] +49 721 98993- [Fax] +49 721 98993- [E-Mail]l...@solute.de<mailto:l...@solute.de> solute GmbH Zeppelinstraße 15 76185 Karlsruhe Germany [Logo Solute] Marken der solute GmbH | brands of solute GmbH [Marken] [Advertising Partner] Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten Webseite | www.solute.de <http://www.solute.de/> Sitz | Registered Office: Karlsruhe Registergericht | Register Court: Amtsgericht Mannheim Registernummer | Register No.: HRB 110579 USt-ID | VAT ID: DE234663798 Informationen zum Datenschutz | Information about privacy policy https://www.solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php Am 21.12.22 um 13:15 schrieb Albert-Jan Roskam: On Dec 21, 2022 06:01, Chris Angelico <mailto:ros...@gmail.com> wrote: On Wed, 21 Dec 2022 at 15:28, Jach Feng <mailto:jf...@ms4.hinet.net> wrote: > That's what I am taking this path under Windows now, the ultimate solution before Windows has shell similar to bash:-) Technically, Windows DOES have a shell similar to bash. It's called bash. :) The trouble is, most people use cmd.exe instead. = I use Git Bash quite a lot: https://gitforwindows.org/ Is that the one you're referring to? -- https://mail.python.org/mailman/listinfo/python-list
Re: sqlite3 double quote behavior
Hey, this might be not the answer you are searching for at all, and it is only a mitigation. But as far as I know, sqlalchemy (and other ORMs) do that for you. I am mention sqlalchemy, because it has got a query builder as well. So you don't have to change your DB-Layer to full ORM, but you could let it build the queries for you. Of course, I know that this would mean a dependency and additional complexity. I just could not leave it unmentioned ;-) Cheers Lars Lars Liedtke Software Entwickler [Tel.] +49 721 98993- [Fax] +49 721 98993- [E-Mail]l...@solute.de<mailto:l...@solute.de> solute GmbH Zeppelinstraße 15 76185 Karlsruhe Germany [Logo Solute] Marken der solute GmbH | brands of solute GmbH [Marken] [Advertising Partner] Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten Webseite | www.solute.de <http://www.solute.de/> Sitz | Registered Office: Karlsruhe Registergericht | Register Court: Amtsgericht Mannheim Registernummer | Register No.: HRB 110579 USt-ID | VAT ID: DE234663798 Informationen zum Datenschutz | Information about privacy policy https://www.solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php Am 13.12.22 um 01:41 schrieb John K. Parejko: Asking here before I file an improvement request issue on the python GitHub: sqlite has a known misfeature with double-quoted strings, whereby they will be interpreted as string literals if they don’t match a valid identifier [1]. The note in the sqlite docs describe a way to disable this misfeature at compile time or by calling an `sqlite3_db_config` C-function, but I don’t see any way to do that in the python sqlite library [2]. Am I missing a way to manage this setting, or is it not available within python? This would be very useful to enable, so that python’s sqlite library will treat queries more like standard sql, instead of this particular version of MySQL. I was just burned by this, where some tests I’d written against an sqlite database did not fail in the way that they “should” have, because of this double-quoted string issue. It doesn’t look like `sqlite3_db_config` is used within the python sqlite3 codebase at all, so this might not be a trivial change? I only see two references to it in the cpython github. Thank you in advance for any suggestions, John 1: https://www.sqlite.org/quirks.html#double_quoted_string_literals_are_accepted 2: https://docs.python.org/3/library/sqlite3.html -- https://mail.python.org/mailman/listinfo/python-list
Re: Superclass static method name from subclass
yes, just use SubClass.foo at least this works for me: class SuperClass: @staticmethod def test(): print("yay") class SubClass(SuperClass): def __init__(self): super().__init__() SubClass.test() subclass = SubClass() Output: python3.11 test.py yay Cheers Lars Lars Liedtke Software Entwickler [Tel.] +49 721 98993- [Fax] +49 721 98993- [E-Mail]l...@solute.de<mailto:l...@solute.de> solute GmbH Zeppelinstraße 15 76185 Karlsruhe Germany [Logo Solute] Marken der solute GmbH | brands of solute GmbH [Marken] [Advertising Partner] Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten Webseite | www.solute.de <http://www.solute.de/> Sitz | Registered Office: Karlsruhe Registergericht | Register Court: Amtsgericht Mannheim Registernummer | Register No.: HRB 110579 USt-ID | VAT ID: DE234663798 Informationen zum Datenschutz | Information about privacy policy https://www.solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php Am 11.11.22 um 17:21 schrieb Ian Pilcher: Is it possible to access the name of a superclass static method, when defining a subclass attribute, without specifically naming the super- class? Contrived example: class SuperClass(object): @staticmethod def foo(): pass class SubClass(SuperClass): bar = SuperClass.foo ^^ Is there a way to do this without specifically naming 'SuperClass'? -- https://mail.python.org/mailman/listinfo/python-list
Re: How to replace an instance method?
Hey, What has not been mentioned yet is simple delegation. Often you want to rewrite a method, maybe have different (more or less) parameters and additionally keep the old methods for backwards compatibility. Or mark it as deprecated at a later point. So you could write the new method and change the old method to call the new method but with the parameters the new method expects. If you explain this in the docstrings as well. Then you do not need to actually replace the method. Or you had a completely different use-case in mind, that I missed. Cheers Lars Lars Liedtke Software Entwickler [Tel.] [Fax] +49 721 98993- [E-Mail]l...@solute.de<mailto:l...@solute.de> solute GmbH Zeppelinstraße 15 76185 Karlsruhe Germany [Logo Solute] Marken der solute GmbH | brands of solute GmbH [Marken] [Advertising Partner] Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten Webseite | www.solute.de <http://www.solute.de/> Sitz | Registered Office: Karlsruhe Registergericht | Register Court: Amtsgericht Mannheim Registernummer | Register No.: HRB 110579 USt-ID | VAT ID: DE234663798 Informationen zum Datenschutz | Information about privacy policy https://www.solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php Am 16.09.22 um 22:55 schrieb Ralf M.: I would like to replace a method of an instance, but don't know how to do it properly. My first naive idea was inst = SomeClass() def new_method(self, param): # do something return whatever inst.method = new_method however that doesn't work: self isn't passed as first parameter to the new inst.method, instead inst.method behaves like a static method. I had a closer look at the decorators classmethod and staticmethod. Unfortunetely I couldn't find a decorator / function "instancemethod" that turns a normal function into an instancemethod. The classmethod documentation contains a reference to the standard type hierarchie, and there is an explanation that an instancemethod is sort of a dynamically created wrapper around a function, which is accessable as __func__. So I modified the last line of the example above to inst.method.__func__ = new_method but got told that __func__ is read only. I found some information about methods in the Descriptor HowTo Guide, but it's about how it works internally and doesn't tell how to solve my problem (at least it doesn't tell me). Now I'm running out of ideas what to try next or what sections of the documentation to read next. Any ideas / pointers? Ralf M. -- https://mail.python.org/mailman/listinfo/python-list
Re: problem downloading python
Hello and welcome, Sadly I don't know about Eset internet security, or why you do not get the choice of letting the installer do that, but you could try to add Python manually to your PATH like it is described in https://www.geeksforgeeks.org/how-to-add-python-to-windows-path/ . But maybe some more windows savvy people than me might chime in to offer better advice ;-) . Cheers Lars Lars Liedtke Software Entwickler [Tel.] [Fax] +49 721 98993- [E-Mail]l...@solute.de<mailto:l...@solute.de> solute GmbH Zeppelinstraße 15 76185 Karlsruhe Germany [Logo Solute] Marken der solute GmbH | brands of solute GmbH [Marken] [Advertising Partner] Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten Webseite | www.solute.de <http://www.solute.de/> Sitz | Registered Office: Karlsruhe Registergericht | Register Court: Amtsgericht Mannheim Registernummer | Register No.: HRB 110579 USt-ID | VAT ID: DE234663798 Informationen zum Datenschutz | Information about privacy policy https://www.solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php Am 14.09.22 um 11:42 schrieb carlharrison: Dear Sir or Madam, I am working on a PC with windows 10 and use Eset internet security. I have tried downloading python 3.10.7 for windows. Using a tutorial I see that a checkbox should appear called "Add python 3/7 to path" but this does not appear whichever version I try to download. I wondered if Eset was stopping this somehow and tried it with Eset switched off but the result is the same. Can you help? Best regards, Carl Harrison. -- https://mail.python.org/mailman/listinfo/python-list
Re: Question about learning Python
Hello and welcome, the answer is a definitive "it depends" ;-) Generally you do not need knowledge in C for learning Python. But I'd say that it will not hurt to have some knowledge. Especially some packages use C-code to extend Python. But it seems to me that you are completely starting to learn how to program. Please correct me if I am wrong. So you can definitely learn how to program with learning Python and you can learn C afterwards if you need to. Cheers Lars -- Lars Liedtke Software Entwickler Phone: Fax:+49 721 98993- E-mail: l...@solute.de solute GmbH Zeppelinstraße 15 76185 Karlsruhe Germany Marken der solute GmbH | brands of solute GmbH billiger.de | Shopping.de Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten Webseite | www.solute.de Sitz | Registered Office: Karlsruhe Registergericht | Register Court: Amtsgericht Mannheim Registernummer | Register No.: HRB 110579 USt-ID | VAT ID: DE234663798 Informationen zum Datenschutz | Information about privacy policy http://solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php Am 07.09.22 um 12:28 schrieb Maruful Islam: I want to start learning python. I have a question about learning python. Is learning C essential or not for learning python? -- https://mail.python.org/mailman/listinfo/python-list
Re: Trying to understand nested loops
Hello, this looks to me like it might be a piece of homework, as it would be given by teachers or professors. This list has got the rule, that members do not solve other's homework. Because very often homework is meant to sit down and think about it. But maybe I interpreted that wrongly, so if you could try to formulate in words what this loop does, I or other people on this list, will be pleased to show you where you might have got things wrong and how it really works. Cheers Lars -- Lars Liedtke Software Entwickler Phone: Fax:+49 721 98993- E-mail: l...@solute.de solute GmbH Zeppelinstraße 15 76185 Karlsruhe Germany Marken der solute GmbH | brands of solute GmbH billiger.de | Shopping.de Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten Webseite | www.solute.de Sitz | Registered Office: Karlsruhe Registergericht | Register Court: Amtsgericht Mannheim Registernummer | Register No.: HRB 110579 USt-ID | VAT ID: DE234663798 Informationen zum Datenschutz | Information about privacy policy http://solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php Am 05.08.22 um 09:34 schrieb ojomooluwatolami...@gmail.com: Hello, I’m new to learning python and I stumbled upon a question nested loops. This is the question below. Can you please how they arrived at 9 as the answer. Thanks var = 0 for i in range(3): for j in range(-2,-7,-2): var += 1 print(var) Sent from my iPhone -- https://mail.python.org/mailman/listinfo/python-list
Re: why function throws an error?
Hey, Which error does it throw? Could you please send the stacktrace as well? Cheers Lars -- Lars Liedtke Software Entwickler Phone: Fax:+49 721 98993- E-mail: l...@solute.de solute GmbH Zeppelinstraße 15 76185 Karlsruhe Germany Marken der solute GmbH | brands of solute GmbH billiger.de | Shopping.de Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten Webseite | www.solute.de Sitz | Registered Office: Karlsruhe Registergericht | Register Court: Amtsgericht Mannheim Registernummer | Register No.: HRB 110579 USt-ID | VAT ID: DE234663798 Informationen zum Datenschutz | Information about privacy policy http://solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php Am 28.06.22 um 09:57 schrieb נתי שטרן: def add_route(self, route): #""" Add a route object, but do not change the :data:`Route.app` #attribute.""" self.routes.append(route) self.router.add(route.rule, route.method, route, name=route.name ) #if DEBUG: route.prepare() -- <https://netanel.ml> -- https://mail.python.org/mailman/listinfo/python-list
Re: Logging into single file from multiple modules in python when TimedRotatingFileHandler is used
The process that is writing the file must be told that rotation has happened for it to work. Other wise all the logs keep being write to the original file via the FD that the process has. logrotate's config include how to tell the process the log file needs reopening. Thanks for clearing. -- Lars Liedtke Software Entwickler Phone: Fax:+49 721 98993- E-mail: l...@solute.de solute GmbH Zeppelinstraße 15 76185 Karlsruhe Germany Marken der solute GmbH | brands of solute GmbH billiger.de | Shopping.de Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten Webseite | www.solute.de Sitz | Registered Office: Karlsruhe Registergericht | Register Court: Amtsgericht Mannheim Registernummer | Register No.: HRB 110579 USt-ID | VAT ID: DE234663798 Informationen zum Datenschutz | Information about privacy policy http://solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php -- https://mail.python.org/mailman/listinfo/python-list
Re: Logging into single file from multiple modules in python when TimedRotatingFileHandler is used
-- Lars Liedtke Software Entwickler Phone: Fax:+49 721 98993- E-mail: l...@solute.de solute GmbH Zeppelinstraße 15 76185 Karlsruhe Germany Marken der solute GmbH | brands of solute GmbH billiger.de | Shopping.de Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten Webseite | www.solute.de Sitz | Registered Office: Karlsruhe Registergericht | Register Court: Amtsgericht Mannheim Registernummer | Register No.: HRB 110579 USt-ID | VAT ID: DE234663798 Informationen zum Datenschutz | Information about privacy policy http://solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php Am 21.06.22 um 11:04 schrieb Chethan Kumar S: I have a main process which makes use of different other modules. And these modules also use other modules. I need to log all the logs into single log file. Due to use of TimedRotatingFileHandler, my log behaves differently after midnight. I got to know why it is so but couldn't get how I can solve it. Issue was because of serialization in logging when multiple processes are involved. Could be unrelated and only a part of a solution, but if you are on a unixoid system, you could use logrotate, instead of TimedRotatingFileHandler. logfrotate ensures that the logging service does not realize, its logs have been rotated. So it can log as if nothing has happened. I don't know, if that helps with your multiple processes, or is a solution at all. Cheers Lars -- https://mail.python.org/mailman/listinfo/python-list
Re: Python & nmap
Ansible has got a shell module, so you could run custom commands on all hosts. But it gets more difficult in parsing the output afterwards. -- Lars Liedtke Software Entwickler Phone: Fax:+49 721 98993- E-mail: l...@solute.de solute GmbH Zeppelinstraße 15 76185 Karlsruhe Germany Marken der solute GmbH | brands of solute GmbH billiger.de | Shopping.de Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten Webseite | www.solute.de Sitz | Registered Office: Karlsruhe Registergericht | Register Court: Amtsgericht Mannheim Registernummer | Register No.: HRB 110579 USt-ID | VAT ID: DE234663798 Informationen zum Datenschutz | Information about privacy policy http://solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php Am 19.05.22 um 21:16 schrieb ^Bart: Maybe it could be a good idea to look at Ansible for copying the Files to all the hosts, because that is one thing ansible is made for. I didn't know it... thanks to share it but... I should start to study it and I don't have not enought free time... but maybe in the future I'll do it! :) For the nmap part: Ansible does not have a module for that (sadly) but is very extensible, so if you start developing something like that in Python, you could as well write an ansible module and combine both, because Ansible itself is written in Python. Ah ok, maybe now I just start to write a bash script because I need to start this work asap, when I'll have one minute I'll try to move the script in Python and after it I could "upload" the work on Ansible! :) Cheers Lars Thanks! ^Bart -- https://mail.python.org/mailman/listinfo/python-list
Re: Python & nmap
# scp "my_file" root@192.168.205.x/my_directory Maybe it could be a good idea to look at Ansible for copying the Files to all the hosts, because that is one thing ansible is made for. For the nmap part: Ansible does not have a module for that (sadly) but is very extensible, so if you start developing something like that in Python, you could as well write an ansible module and combine both, because Ansible itself is written in Python. Cheers Lars -- Lars Liedtke Software Entwickler Phone: Fax:+49 721 98993- E-mail: l...@solute.de solute GmbH Zeppelinstraße 15 76185 Karlsruhe Germany Marken der solute GmbH | brands of solute GmbH billiger.de | Shopping.de Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten Webseite | www.solute.de Sitz | Registered Office: Karlsruhe Registergericht | Register Court: Amtsgericht Mannheim Registernummer | Register No.: HRB 110579 USt-ID | VAT ID: DE234663798 Informationen zum Datenschutz | Information about privacy policy http://solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php -- https://mail.python.org/mailman/listinfo/python-list
Re: Why no list as dict key?
Thx, didn't see it that way yet. -- Lars Liedtke Software Entwickler Phone: Fax:+49 721 98993- E-mail: l...@solute.de solute GmbH Zeppelinstraße 15 76185 Karlsruhe Germany Marken der solute GmbH | brands of solute GmbH billiger.de | Shopping.de Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten Webseite | www.solute.de Sitz | Registered Office: Karlsruhe Registergericht | Register Court: Amtsgericht Mannheim Registernummer | Register No.: HRB 110579 USt-ID | VAT ID: DE234663798 Informationen zum Datenschutz | Information about privacy policy http://solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php Am 25.04.22 um 15:54 schrieb Peter J. Holzer: On 2022-04-25 15:13:19 +0200, Lars Liedtke wrote: May I stupidly ask, why one would want to use an iterable (even immutable) as dict key? A string is also an immutable iterable, so this is probably even the most common case. As for more complex data structures: * Tuples or immutable dicts are a good fit if want to group records by subset of their attributes (think "group by" in SQL) * Objects in general are often though of as units, even if they have composite values and you might want to look up something by that value. hp -- https://mail.python.org/mailman/listinfo/python-list
Re: Why no list as dict key?
May I stupidly ask, why one would want to use an iterable (even immutable) as dict key? I thought keys were meant to be something "singular". And yes you could also combine a string to be a key, and if you combine a string it would be somehow the same as a tuple. But anyways I still fail to see the application for that, which is most propably to ignorance rather than criticism. Cheers Lars -- Lars Liedtke Software Entwickler Phone: Fax:+49 721 98993- E-mail: l...@solute.de solute GmbH Zeppelinstraße 15 76185 Karlsruhe Germany Marken der solute GmbH | brands of solute GmbH billiger.de | Shopping.de Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten Webseite | www.solute.de Sitz | Registered Office: Karlsruhe Registergericht | Register Court: Amtsgericht Mannheim Registernummer | Register No.: HRB 110579 USt-ID | VAT ID: DE234663798 Informationen zum Datenschutz | Information about privacy policy http://solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php Am 21.04.22 um 07:00 schrieb Chris Angelico: On Thu, 21 Apr 2022 at 13:23, Abdur-Rahmaan Janhangeer wrote: Assumes checking for object equality before inserting. If they are they same, do we need different hashes? The point of the hash is to find things that are equal. That's why 1234, 1234.0, and 0j+1234.0 all have the same hash. If equality changes, the hash does too. It's certainly possible to have the hash come from object identity, but then so must equality. If you want that, it's easy to do - just create your own object for the state, rather than using a list. But then you have to use the original object to look things up, instead of matching by the data. Hashes are simply a short-hand for equality. That's all. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?
Additionally, which datatype would you expect them to be returned in? One could argument for int or float (Decimal?), both could be valid datatypes, depending on how exact you might want them, while the second is the time base of SI units. Cheers Lars -- Lars Liedtke Software Entwickler Phone: Fax:+49 721 98993- E-mail: l...@solute.de solute GmbH Zeppelinstraße 15 76185 Karlsruhe Germany Marken der solute GmbH | brands of solute GmbH billiger.de | Shopping.de Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten Webseite | www.solute.de Sitz | Registered Office: Karlsruhe Registergericht | Register Court: Amtsgericht Mannheim Registernummer | Register No.: HRB 110579 USt-ID | VAT ID: DE234663798 Informationen zum Datenschutz | Information about privacy policy http://solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php Am 14.04.22 um 17:01 schrieb Paul Bryan: I think because minutes and hours can easily be composed by multiplying seconds. days is separate because you cannot compose days from seconds; leap seconds are applied to days at various times, due to irregularities in the Earth's rotation. On Thu, 2022-04-14 at 15:38 +0200, Loris Bennett wrote: "Loris Bennett" writes: Hi, With Python 3.9.2 I get $ import datetime $ s = "1-00:01:01" $ t = datetime.datetime.strptime(s, "%d-%H:%M:%S") $ d = datetime.timedelta(days=t.day, hours=t.hour, minutes=t.minute, seconds=t.second) $ d.days 1 $ d.seconds 61 $ d.minutes AttributeError: 'datetime.timedelta' object has no attribute 'minutes' Is there a particular reason why there are no attributes 'minutes' and 'hours and the attribute 'seconds' encompasses is the entire fractional day? That should read: Is there a particular reason why there are no attributes 'minutes' and 'hours' and the attribute 'seconds' encompasses the entire fractional day? Cheers, Loris -- Dr. Loris Bennett (Herr/Mr) ZEDAT, Freie Universität Berlin Email loris.benn...@fu-berlin.de -- https://mail.python.org/mailman/listinfo/python-list
How do you log in your projects?
Hello, inspired by this thread https://mail.python.org/pipermail/python-list/2022-February/905167.html I finally came around to send in this question. I know how to use python logging generally. Being on the DevOps-Side of things at the moment, I naturally began liking to run tools, which not only have logging, but also have different levels of logging configurable, because often when you run a couple of different services and software projects, logging is often the first help you turn to, and sometimes it is the only way to know what is going on. Not that the code of most (FLOSS) software is not available, but you simply do not have the time to read into the code of every piece of software you run. So of course I want to write software on my own, if I have to or wpuld like to, that has got a decent amount of logging. But how often to actually log things? Of course the obvious answer is "it depends". So how do you do your logging? - On a line per line basis? on a function/method basis? - Do you use decorators to mark beginnings and ends of methods/functions in log files? - Which kind of variable contents do you write into your logfiles? Of course you shouldn't leak secrets... - How do you decide, which kind of log message goes into which level? - How do you prevent logging cluttering your actual code? Maybe there are some questions I forgot, so please feel free to add whatever you think might help finding the best way of logging (tm) Cheers Lars -- punkt.de GmbH Lars Liedtke .infrastructure Kaiserallee 13a 76133 Karlsruhe Tel. +49 721 9109 500 https://infrastructure.punkt.de i...@punkt.de AG Mannheim 108285 Geschäftsführer: Jürgen Egeling, Daniel Lienert, Fabian Stein -- https://mail.python.org/mailman/listinfo/python-list
Re: Best way to check if there is internet?
P.S.: for ping a startingpoint can be icmplib, for dns dnspython and for http requests. But consider as well if you want to check for IPv4 and/or IPv6 Connectivity. Am 07.02.22 um 13:47 schrieb Lars Liedtke: Each Browser is doing it differently and even Windows or Linux-Desktopmanagers (NetworkManager). I have had cases, where one tool told me I had Internet and another one I hadn't. So What Chris Angelico wrote is propably the best way, ping e.g. Google, do a DNS lookup and try http for Status 200. Each with its own Errorhandling and if you have got all three, then it is propable that you have "Internet". Cheers Lars Am 07.02.22 um 10:33 schrieb Abdur-Rahmaan Janhangeer: Popular browsers tell: No internet connection detected. A function that goes in the same sense. Unless they too are pinging Google.com to check ... Kind Regards, Abdur-Rahmaan Janhangeer about <https://compileralchemy.github.io/> | blog <https://www.pythonkitchen.com> github <https://github.com/Abdur-RahmaanJ> Mauritius On Mon, Feb 7, 2022 at 1:28 PM Chris Angelico wrote: On Mon, 7 Feb 2022 at 20:18, Abdur-Rahmaan Janhangeer wrote: Greetings, Using the standard library or 3rd party libraries, what's the best way to check if there is internet? Checking if google.com is reachable is good but I wonder if there is a more native, protocol-oriented way of knowing? What do you mean by "if there is internet"? How low a level of connection do you want to test? You could ping an IP address that you know and can guarantee will respond. You could attempt a DNS lookup. You could try an HTTP request. Each one can fail in different ways, for different reasons. It's best to test what you actually care about. Even this URL recommends checking if a domain is up as a way to check for internet connectivity: https://www.ibm.com/support/pages/checking-network-connectivity-when-using-python-and-ibm-resilient-circuits That talks about a misconfigured proxy as being the most likely cause. Is that something you're trying to test for? There is no single concept of "there is internet". (Other than, in a trivial sense, that the internet does exist.) What you need to know is "can I use the internet?", and ultimately, that depends on what you need it to do. ChrisA -- https://mail.python.org/mailman/listinfo/python-list -- punkt.de GmbH Lars Liedtke .infrastructure Kaiserallee 13a 76133 Karlsruhe Tel. +49 721 9109 500 https://infrastructure.punkt.de i...@punkt.de AG Mannheim 108285 Geschäftsführer: Jürgen Egeling, Daniel Lienert, Fabian Stein -- https://mail.python.org/mailman/listinfo/python-list
Re: Best way to check if there is internet?
Each Browser is doing it differently and even Windows or Linux-Desktopmanagers (NetworkManager). I have had cases, where one tool told me I had Internet and another one I hadn't. So What Chris Angelico wrote is propably the best way, ping e.g. Google, do a DNS lookup and try http for Status 200. Each with its own Errorhandling and if you have got all three, then it is propable that you have "Internet". Cheers Lars Am 07.02.22 um 10:33 schrieb Abdur-Rahmaan Janhangeer: Popular browsers tell: No internet connection detected. A function that goes in the same sense. Unless they too are pinging Google.com to check ... Kind Regards, Abdur-Rahmaan Janhangeer about <https://compileralchemy.github.io/> | blog <https://www.pythonkitchen.com> github <https://github.com/Abdur-RahmaanJ> Mauritius On Mon, Feb 7, 2022 at 1:28 PM Chris Angelico wrote: On Mon, 7 Feb 2022 at 20:18, Abdur-Rahmaan Janhangeer wrote: Greetings, Using the standard library or 3rd party libraries, what's the best way to check if there is internet? Checking if google.com is reachable is good but I wonder if there is a more native, protocol-oriented way of knowing? What do you mean by "if there is internet"? How low a level of connection do you want to test? You could ping an IP address that you know and can guarantee will respond. You could attempt a DNS lookup. You could try an HTTP request. Each one can fail in different ways, for different reasons. It's best to test what you actually care about. Even this URL recommends checking if a domain is up as a way to check for internet connectivity: https://www.ibm.com/support/pages/checking-network-connectivity-when-using-python-and-ibm-resilient-circuits That talks about a misconfigured proxy as being the most likely cause. Is that something you're trying to test for? There is no single concept of "there is internet". (Other than, in a trivial sense, that the internet does exist.) What you need to know is "can I use the internet?", and ultimately, that depends on what you need it to do. ChrisA -- https://mail.python.org/mailman/listinfo/python-list -- punkt.de GmbH Lars Liedtke .infrastructure Kaiserallee 13a 76133 Karlsruhe Tel. +49 721 9109 500 https://infrastructure.punkt.de i...@punkt.de AG Mannheim 108285 Geschäftsführer: Jürgen Egeling, Daniel Lienert, Fabian Stein -- https://mail.python.org/mailman/listinfo/python-list
Re: Why dict.setdefault() has value as optional?
This is a quite philosophical queston if you look at it in general: "What value do you give a variable, that is not set?" You are right, at first it seems strange to have a default of None. But how do you want to signal that no default is set yet? Especially if you think of a dict that can have multiple keys with each different values of different types? Have fun in the rabbithole ;-) Cheers Lars Am 02.02.22 um 13:54 schrieb Marco Sulla: Just out of curiosity: why dict.setdefault() has the default parameter that well, has a default value (None)? I used setdefault in the past, but I always specified a value. What's the use case of setting None by default? -- punkt.de GmbH Lars Liedtke .infrastructure Kaiserallee 13a 76133 Karlsruhe Tel. +49 721 9109 500 https://infrastructure.punkt.de i...@punkt.de AG Mannheim 108285 Geschäftsführer: Jürgen Egeling, Daniel Lienert, Fabian Stein -- https://mail.python.org/mailman/listinfo/python-list
Re: Gunicorn - HTTP and HTTPS in the same instance?
server { listen [::]:80; listen 80; server_name api.familie-liedtke.net; location / { return 301 https://$host$request_uri; } include /usr/local/etc/nginx/include/letsencrypt.conf; } server { listen 443 ssl http2; listen [::]:443 ssl http2; server_name api.familie-liedtke.net; ssl_certificate /usr/local/etc/ssl/certs/api.familie-liedtke.net/fullchain.pem; ssl_certificate_key /usr/local/etc/ssl/certs/api.familie-liedtke.net/privkey.pem; root /var/www/api; location /weather/{ access_log /var/log/nginx/weather-access.log; include uwsgi_params; rewrite ^/weather(/.*)$ $1 break; uwsgi_pass unix:///tmp/uwsgi.sock; } include /usr/local/etc/nginx/include/ssl.conf; } This is my config for a flask app on uwsgi. granted it is a bit more than the 10 lines I said. But there is not much sophistication to it. Am 08.01.22 um 17:25 schrieb Skip Montanaro: Thanks all. I was hoping to get away without something more sophisticated like NGINX. This is just a piddly little archive of an old mailing list running on a single-core Ubuntu VM somewhere on the East Coast. Speed is not a real requirement. Load balancing seemed like overkill to me. Still, I guess if it has to be, then it has to be. Skip -- punkt.de GmbH Lars Liedtke .infrastructure Kaiserallee 13a 76133 Karlsruhe Tel. +49 721 9109 500 https://infrastructure.punkt.de i...@punkt.de AG Mannheim 108285 Geschäftsführer: Jürgen Egeling, Daniel Lienert, Fabian Stein -- https://mail.python.org/mailman/listinfo/python-list
Re: Gunicorn - HTTP and HTTPS in the same instance?
I think this is more a thing of apporach. Nginx is quite simple to install and a config doing nothing else than redirecting https to https and proxying requests to a service (whichever tat is, in your case gunicorn) can become a nobrainer. That is what it became for me. Additionally the config for only this functionality are less than 10. So it's may seem complicated at first, but is way less oncxe you got used to it. Cheers Lars Am 08.01.22 um 17:25 schrieb Skip Montanaro: Thanks all. I was hoping to get away without something more sophisticated like NGINX. This is just a piddly little archive of an old mailing list running on a single-core Ubuntu VM somewhere on the East Coast. Speed is not a real requirement. Load balancing seemed like overkill to me. Still, I guess if it has to be, then it has to be. Skip -- punkt.de GmbH Lars Liedtke .infrastructure Kaiserallee 13a 76133 Karlsruhe Tel. +49 721 9109 500 https://infrastructure.punkt.de i...@punkt.de AG Mannheim 108285 Geschäftsführer: Jürgen Egeling, Daniel Lienert, Fabian Stein -- https://mail.python.org/mailman/listinfo/python-list
Re: Call julia from Python: which package?
Additionally I'd like to ask, if you e.g. used pandas and numpy before you make the effort of rewriting everything. Yes python is slower than compiled languages, but especially with numpy you can make use of compiled code underneath. Of course this could mean rewriting some existing code but staying in python. If you have done all of that or there are other impediments, then of course no one will hold you back. Am 17.12.21 um 16:12 schrieb Dan Stromberg: > On Fri, Dec 17, 2021 at 7:02 AM Albert-Jan Roskam > wrote: > >> Hi, >> >> I have a Python program that uses Tkinter for its GUI. It's rather slow so >> I hope to replace many or all of the non-GUI parts by Julia code. Has >> anybody experience with this? Any packages you can recommend? I found three >> alternatives: >> >> * https://pyjulia.readthedocs.io/en/latest/usage.html# >> * https://pypi.org/project/juliacall/ >> * https://github.com/JuliaPy/PyCall.jl >> >> Thanks in advance! >> > I have zero Julia experience. > > I thought I would share this though: > https://stromberg.dnsalias.org/~strombrg/speeding-python/ > > Even if you go the Julia route, it's probably still best to profile your > Python code to identify the slow ("hot") spots, and rewrite only them. -- punkt.de GmbH Lars Liedtke .infrastructure Kaiserallee 13a 76133 Karlsruhe Tel. +49 721 9109 500 https://infrastructure.punkt.de i...@punkt.de AG Mannheim 108285 Geschäftsführer: Jürgen Egeling, Daniel Lienert, Fabian Stein -- https://mail.python.org/mailman/listinfo/python-list
Re: Create a contact book
> Here at Homeworks Anonymous, the first step is admitting that what you > have is a homework problem. :) > > ChrisA -- punkt.de GmbH Lars Liedtke .infrastructure Kaiserallee 13a 76133 Karlsruhe Tel. +49 721 9109 500 https://infrastructure.punkt.de i...@punkt.de AG Mannheim 108285 Geschäftsführer: Jürgen Egeling, Daniel Lienert, Fabian Stein -- https://mail.python.org/mailman/listinfo/python-list
Re: memory consumption
Hello Alexej, May I stupidly ask, why you care about that in general? Please don't get me wrong I don't want to criticize you, this is rather meant to be a (thought) provoking question. Normally your OS-Kernel and the Python-Interpreter get along pretty well and whenthere is free memory to be had, or not the necessity to release allocated memory then why force this? Python will release memory when needed by running the gc. Have you tried running your task over all the data you have? Did it crash your system or prevent other processes from having enough memory? If not: why care? I know that there can be (good) reasons to care, but as long as your tasks run fine, without clogging your system, in my opinion there might be nothing to worry about. Cheers Lars Am 29.03.21 um 12:12 schrieb Alexey: > Hello everyone! > I'm experiencing problems with memory consumption. > > I have a class which is doing ETL job. What`s happening inside: > - fetching existing objects from DB via SQLAchemy > - iterate over raw data > - create new/update existing objects > - commit changes > > Before processing data I create internal cache(dictionary) and store all > existing objects in it. > Every 1 items I do bulk insert and flush. At the end I run commit command. > > Problem. Before executing, my interpreter process weighs ~100Mb, after first > run memory increases up to 500Mb > and after second run it weighs 1Gb. If I will continue to run this class, > memory wont increase, so I think > it's not a memory leak, but rather Python wont release allocated memory back > to OS. Maybe I'm wrong. > > What I tried after executing: > - gc.collect() > - created snapshots with tracemalloc and searched for some garbage, diff = >smapshot_before_run - smapshot_after_run > - searched for links with "objgraph" library to internal cache(dictionary >containing elements from DB) > - cleared the cache(dictionary) > - db.session.expire_all() > > This class is a periodic celery task. So when each worker executes this class > at least two times, > all celery workers need 1Gb of RAM. Before celery there was a cron script and > this class was executed via API call > and the problem was the same. So no matter how I run, interpreter consumes > 1Gb of RAM after two runs. > > I see few solutions to this problem > 1. Execute this class in separate process. But I had few errors when the same > SQLAlchemy connection being shared > between different processes. > 2. Restart celery worker after executing this task by throwing exception. > 3. Use separate queue for such tasks, but then worker will stay idle most of > the time. > All this is looks like a crutch. Do I have any other options ? > > I'm using: > Python - 3.6.13 > Celery - 4.1.0 > Flask-RESTful - 0.3.6 > Flask-SQLAlchemy - 2.3.2 > > Thanks in advance! -- --- punkt.de GmbH Lars Liedtke .infrastructure Kaiserallee 13a 76133 Karlsruhe Tel. +49 721 9109 500 https://infrastructure.punkt.de i...@punkt.de AG Mannheim 108285 Geschäftsführer: Jürgen Egeling, Daniel Lienert, Fabian Stein -- https://mail.python.org/mailman/listinfo/python-list
Re: Pip standard error warning about dependency resolver
I understand your problem and I know that sometimes it is not possible to do it differently. But as far as my understanding goes, your backend operations should not die on outputs on stderr. I understand that is what return values are for and as long as the return value is 0 everything went without error, even though there might be output on stderr. That said. As far as I know you could try the commandline option for using the new resolver explicitly. I don't know if there is an option for "silent" Cheers Lars Am 23.02.21 um 17:48 schrieb adam@gmail.com: > I started seeing this sometimes from pip: > > After October 2020 you may experience errors when installing or updating > packages. This is because pip will change the way that it resolves dependency > conflicts. > > Yeah, sure, that's something to consider. We seem fine with the new resolver. > Is there a way to suppress it? We have some back end operations that fail > when we get output on standard error, and they're dying from that notice. -- --- punkt.de GmbH Lars Liedtke .infrastructure Kaiserallee 13a 76133 Karlsruhe Tel. +49 721 9109 500 https://infrastructure.punkt.de i...@punkt.de AG Mannheim 108285 Geschäftsführer: Jürgen Egeling, Daniel Lienert, Fabian Stein -- https://mail.python.org/mailman/listinfo/python-list