Re: Waht do you think about my repeated_timer class

2022-02-02 Thread Cecil Westerhof via Python-list
Chris Angelico writes: > On Thu, 3 Feb 2022 at 15:43, Cecil Westerhof via Python-list > wrote: >> >> Chris Angelico writes: >> >> >> > (Side point: The OP's code is quite inefficient, as it creates a new >> >> > thread for each reiteration, but there's nothing wrong with that if >> >> > you're

Re: Waht do you think about my repeated_timer class

2022-02-02 Thread Cecil Westerhof via Python-list
Cecil Westerhof writes: > I need (sometimes) to repeatedly execute a function. For this I wrote > the below class. What do you think about it? I wrote some unit test for the class. Is this the correct way to do this? For example in test_correct_params_no_start I check four things. Some people sa

Re: Waht do you think about my repeated_timer class

2022-02-02 Thread Cecil Westerhof via Python-list
2qdxy4rzwzuui...@potatochowder.com writes: > FWIW, I'd find some way to tell users the units (seconds, milliseconds, > fortnights, etc.) instead of making them wade through your code to find > the call to (and possibly the [broken] help text of) Timer. You mean with docstring? -- Cecil Westerho

Re: Waht do you think about my repeated_timer class

2022-02-02 Thread Chris Angelico
On Thu, 3 Feb 2022 at 15:43, Cecil Westerhof via Python-list wrote: > > Chris Angelico writes: > > >> > (Side point: The OP's code is quite inefficient, as it creates a new > >> > thread for each reiteration, but there's nothing wrong with that if > >> > you're looking for something simple.) > >>

Re: Waht do you think about my repeated_timer class

2022-02-02 Thread Cecil Westerhof via Python-list
Chris Angelico writes: >> > (Side point: The OP's code is quite inefficient, as it creates a new >> > thread for each reiteration, but there's nothing wrong with that if >> > you're looking for something simple.) >> >> It is just something I wrote fast. How could I do this in a better way? > > I'

Re: Waht do you think about my repeated_timer class

2022-02-02 Thread Chris Angelico
On Thu, 3 Feb 2022 at 15:28, <2qdxy4rzwzuui...@potatochowder.com> wrote: > > On 2022-02-03 at 15:07:22 +1100, > Chris Angelico wrote: > > > On Thu, 3 Feb 2022 at 14:52, <2qdxy4rzwzuui...@potatochowder.com> wrote: > > > > > > On 2022-02-03 at 12:39:43 +1100, > > > Cameron Simpson wrote: > > > > >

Re: Waht do you think about my repeated_timer class

2022-02-02 Thread 2QdxY4RzWzUUiLuE
On 2022-02-03 at 15:07:22 +1100, Chris Angelico wrote: > On Thu, 3 Feb 2022 at 14:52, <2qdxy4rzwzuui...@potatochowder.com> wrote: > > > > On 2022-02-03 at 12:39:43 +1100, > > Cameron Simpson wrote: > > > > > You have: > > > > > > def _check_interval(self, interval): > > > if not type

Re: Waht do you think about my repeated_timer class

2022-02-02 Thread Chris Angelico
On Thu, 3 Feb 2022 at 14:52, <2qdxy4rzwzuui...@potatochowder.com> wrote: > > On 2022-02-03 at 12:39:43 +1100, > Cameron Simpson wrote: > > > You have: > > > > def _check_interval(self, interval): > > if not type(interval) in [int, float]: > > raise TypeError('{} is not nume

Re: Waht do you think about my repeated_timer class

2022-02-02 Thread 2QdxY4RzWzUUiLuE
On 2022-02-03 at 12:39:43 +1100, Cameron Simpson wrote: > You have: > > def _check_interval(self, interval): > if not type(interval) in [int, float]: > raise TypeError('{} is not numeric'.format(interval)) > > This check is better written: > > if not isinstance(inte

Re: Waht do you think about my repeated_timer class

2022-02-02 Thread Cecil Westerhof via Python-list
Cameron Simpson writes: > You have: > > def _check_interval(self, interval): > if not type(interval) in [int, float]: > raise TypeError('{} is not numeric'.format(interval)) > > This check is better written: > > if not isinstance(interval, (int,float)): > > which handl

Re: Data unchanged when passing data to Python in multiprocessing shared memory

2022-02-02 Thread Chris Angelico
On Thu, 3 Feb 2022 at 13:32, Avi Gross via Python-list wrote: > > Jen, > > I would not be shocked at incompatibilities in the system described making it > hard to exchange anything, including text, but am not clear if there is a > limitation of four bytes in what can be shared. For me, a charact

Re: Data unchanged when passing data to Python in multiprocessing shared memory

2022-02-02 Thread Avi Gross via Python-list
Jen, I would not be shocked at incompatibilities in the system described making it hard to exchange anything, including text, but am not clear if there is a limitation of four bytes in what can be shared. For me, a character string can use any number of contiguous bytes in memory that some kind

Re: Waht do you think about my repeated_timer class

2022-02-02 Thread Chris Angelico
On Thu, 3 Feb 2022 at 12:24, Cecil Westerhof via Python-list wrote: > > Chris Angelico writes: > > > On Thu, 3 Feb 2022 at 09:33, Barry wrote: > > (Side point: The OP's code is quite inefficient, as it creates a new > > thread for each reiteration, but there's nothing wrong with that if > > you'

Re: Waht do you think about my repeated_timer class

2022-02-02 Thread Cameron Simpson
You have: def _check_interval(self, interval): if not type(interval) in [int, float]: raise TypeError('{} is not numeric'.format(interval)) This check is better written: if not isinstance(interval, (int,float)): which handles subclasses of these types (but note that

Re: Waht do you think about my repeated_timer class

2022-02-02 Thread Cecil Westerhof via Python-list
Cecil Westerhof writes: >> (regardless of your OS). The same could be done with this timer; an >> __exit__ method would make a lot of sense here, and would allow the >> timer to be used in a with block to govern its execution. (It also >> isn't really necessary, but if you want a good Pythonic wa

Re: Waht do you think about my repeated_timer class

2022-02-02 Thread Cecil Westerhof via Python-list
Chris Angelico writes: > On Thu, 3 Feb 2022 at 09:33, Barry wrote: > (Side point: The OP's code is quite inefficient, as it creates a new > thread for each reiteration, but there's nothing wrong with that if > you're looking for something simple.) It is just something I wrote fast. How could I

Re: Waht do you think about my repeated_timer class

2022-02-02 Thread Chris Angelico
On Thu, 3 Feb 2022 at 09:33, Barry wrote: > > > > > On 2 Feb 2022, at 21:12, Marco Sulla wrote: > > > > You could add a __del__ that calls stop :) > > Didn’t python3 make this non deterministic when del is called? > > I thought the recommendation is to not rely on __del__ in python3 code. > The

Re: Waht do you think about my repeated_timer class

2022-02-02 Thread Barry
> On 2 Feb 2022, at 21:12, Marco Sulla wrote: > > You could add a __del__ that calls stop :) Didn’t python3 make this non deterministic when del is called? I thought the recommendation is to not rely on __del__ in python3 code. Barry > >> On Wed, 2 Feb 2022 at 21:23, Cecil Westerhof via Py

Re: Data unchanged when passing data to Python in multiprocessing shared memory

2022-02-02 Thread Barry
> On 2 Feb 2022, at 18:19, Jen Kris via Python-list > wrote: > > It's not clear to me from the struct module whether it can actually > auto-detect endianness. It is impossible to auto detect endian in the general case. > I think it must be specified, just as I had to do with int.from_byte

Re: Waht do you think about my repeated_timer class

2022-02-02 Thread Marco Sulla
You could add a __del__ that calls stop :) On Wed, 2 Feb 2022 at 21:23, Cecil Westerhof via Python-list wrote: > > I need (sometimes) to repeatedly execute a function. For this I wrote > the below class. What do you think about it? > from threading import Timer > > > > class repeated_tim

Waht do you think about my repeated_timer class

2022-02-02 Thread Cecil Westerhof via Python-list
I need (sometimes) to repeatedly execute a function. For this I wrote the below class. What do you think about it? from threading import Timer class repeated_timer(object): def __init__(self, fn, interval, start = False): if not callable(fn): raise Ty

Re: Data unchanged when passing data to Python in multiprocessing shared memory

2022-02-02 Thread Dennis Lee Bieber
On Wed, 2 Feb 2022 19:16:19 +0100 (CET), Jen Kris declaimed the following: >It's not clear to me from the struct module whether it can actually >auto-detect endianness.  I think it must be specified, just as I had to do >with int.from_bytes().  In my case endianness was dictated by how the four

Re: Data unchanged when passing data to Python in multiprocessing shared memory

2022-02-02 Thread Jen Kris via Python-list
An ASCII string will not work.  If you convert 32894 to an ascii string you will have five bytes, but you need four.  In my original post I showed the C program I used to convert any 32-bit number to 4 bytes.  Feb 2, 2022, 10:16 by python-list@python.org: > I applaud trying to find the right

Re: Data unchanged when passing data to Python in multiprocessing shared memory

2022-02-02 Thread Jen Kris via Python-list
It's not clear to me from the struct module whether it can actually auto-detect endianness.  I think it must be specified, just as I had to do with int.from_bytes().  In my case endianness was dictated by how the four bytes were populated, starting with the zero bytes on the left.  Feb 1, 202

Re: Data unchanged when passing data to Python in multiprocessing shared memory

2022-02-02 Thread Avi Gross via Python-list
I applaud trying to find the right solution but wonder if a more trivial solution is even being considered. It ignores big and little endians and just converts your data into another form and back. If all you want to do is send an integer that fit in 32 bits or 64 bits, why not convert it to a

Re: http.client and dns lookups

2022-02-02 Thread Dieter Maurer
Michael Welle wrote at 2022-2-1 19:28 +0100: > ... >That doesn't happen when the 'real' issue occurs. Attaching strace to >the Python process I can see that resolv.conf is stat'ed and open'ed. I >guess now I'm more confused than before ;). There must be an additional >condition that I'm missing. T

Re: Why dict.setdefault() has value as optional?

2022-02-02 Thread Marco Sulla
On Wed, 2 Feb 2022 at 14:34, Lars Liedtke wrote: > > This is a quite philosophical queston if you look at it in general: > "What value do you give a variable, that is not set?" Maybe I expressed my question badly. My existential doubt is why setdefault has an optional parameter for the value and

Re: Data unchanged when passing data to Python in multiprocessing shared memory

2022-02-02 Thread Dennis Lee Bieber
On Wed, 2 Feb 2022 00:40:22 +0100 (CET), Jen Kris declaimed the following: > > breakup = int.from_bytes(byte_val, "big") >print("this is breakup " + str(breakup)) > >Python prints:  this is breakup 32894 > >Note that I had to switch from little endian to big endian.  Python is little >endian by

Re: Why dict.setdefault() has value as optional?

2022-02-02 Thread Lars Liedtke
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

Why dict.setdefault() has value as optional?

2022-02-02 Thread 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? -- https://mail.python.org/mailman/listinfo/python-list

Re: Data unchanged when passing data to Python in multiprocessing shared memory

2022-02-02 Thread Barry Scott
> On 1 Feb 2022, at 23:40, Jen Kris wrote: > > Barry, thanks for your reply. > > On the theory that it is not yet possible to pass data from a non-Python > language to Python with multiprocessing.shared_memory, I bypassed the problem > by attaching 4 bytes to my FIFO pipe message from NASM