Re: Threading plus multiprocessing plus cv2 error

2020-08-29 Thread Stephane Tougard via Python-list
On 2020-08-29, Dennis Lee Bieber  wrote:
>   Under Linux, multiprocessing creates processes using fork(). That means
> that, for some fraction of time, you have TWO processes sharing the same
> thread and all that entails (if it doesn't overlay the forked process with
> a new executable, they are sharing the thread until the thread exits).
> same error condition even with the sleep(1) in place.

I'm not even that makes sense, how 2 processes can share a thread ?


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Threading plus multiprocessing plus cv2 error

2020-08-30 Thread Stephane Tougard via Python-list
On 2020-08-30, Chris Angelico  wrote:
>> I'm not even that makes sense, how 2 processes can share a thread ?
>>
> They can't. However, they can share a Thread object, which is the
> Python representation of a thread. That can lead to confusion, and
> possibly the OP's error (I don't know for sure, I'm just positing).

A fork() is a copy of a process in a new process. If this process has a
thread (or several), they are part of the copy and the new process has
those threads as well.

Unless there is a memory sharing between those processes, what happens
on one thread in the first process is totally independant of what
happens in the copy of this thread in the other process.

I'm not specialist on multi-threading in Python, but it should not
change anything. Both processes (father and child) don't share the same
thread, each one has its own copy of the thread.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Threading plus multiprocessing plus cv2 error

2020-08-30 Thread Stephane Tougard via Python-list
On 2020-08-30, Barry  wrote:
>*  The child process is created with a single thread—the one that
>   called fork().  The entire virtual address space of the parent is
>   replicated in the child, including the states of mutexes,
>   condition variables, and other pthreads objects; the use of
>   pthread_atfork(3) may be helpful for dealing with problems that

Indeed, I have a similar entry on my NetBSD:

 In case of a threaded program, only the thread calling fork() is
 still running in the child processes.

Very interesting.
-- 
https://mail.python.org/mailman/listinfo/python-list


Use of a variable in parent loop

2020-09-25 Thread Stephane Tougard via Python-list


Hello All,

I've been working with Perl a long time and recently started to use
Python. I've been surprised by one behavior of Python. 

In Perl:

===PERL===
#!/usr/pkg/bin/perl

use strict;

if(4 == 4)
{
my $name = "Stephane";
print("$name\n" 
}
print("Out $name\n");
=

This code will trigger an error because $name is declared inside the if
and is not usable outside of the block code. That looks logic to me.

===PYTHON===
#!/usr/local/bin/python
if 4 == 4:
name = "Stephane"
print(name)
pass

print("Out {}".format(name))


The exact same code in Python works fine, the variable name is used
outside of the if block even it has been declared inside.

This does not look right to me. Can we change this behavior or is there
any point to keep it this way ?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Use of a variable in parent loop

2020-09-26 Thread Stephane Tougard via Python-list
On 2020-09-26, Terry Reedy  wrote:
> Noise.  Only 'pass' when there is no other code.

Why ?

I use pass and continue each time to break a if or a for because emacs
understands it and do not break the indentation.

Is there any other instruction to end a if than pass and ensure Emacs
does not break the indentation during a copy paste or an indent-region ?

> Aside from not breaking most every existing Python program?  If block 
> scoped, one would have to add an otherwise useless fake declaration 
> before the block to use the name outside the block.  Python tries to 
> avoid boilerplate code.

I'm not talking about a general change in Python as a language, I'm
talking about a module who would enforce a block namespace as it works with
C or Perl (and many).

In Perl, use strict will break any non-strict code. So each is free to
chose between strict and not strict.

Anyway, there's no perfect language, the point is to know it. It's just
confusing I still have to declare or not declare an object depending on
the action I have with it. 

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Use of a variable in parent loop

2020-09-27 Thread Stephane Tougard via Python-list
On 2020-09-27, [email protected] 
<[email protected]> wrote:
> As ChrisA noted, Python almost always Just Works without declarations.
> If you find yourself with a lot of global and/or nonlocal statements,
> perhaps you're [still] thinking in another language.


I don't really agree with that, trying to use an undeclared
object/variable/whatever :

Python 3.7.7 (default, Aug 22 2020, 17:07:43) 
[GCC 7.4.0] on netbsd9
Type "help", "copyright", "credits" or "license" for more information.
>>> print(name)
Traceback (most recent call last):
  File "", line 1, in 
  NameError: name 'name' is not defined
  >>> 

You can say it's not the "declaration" the issue, it's the "definition",
that's just a matter of vocabulary and it does not answer the question.

In many non declarative language, if I do print($var), it just prints
and undefined value with returning an error.


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Use of a variable in parent loop

2020-09-27 Thread Stephane Tougard via Python-list
On 2020-09-27, Stefan Ram  wrote:
>>Is there any other instruction to end a if than pass and ensure Emacs
>>does not break the indentation during a copy paste or an indent-region ?
>
>   We usually do not wish to tie our code to a defective editor.
>   I use vi, and can assure you that there is no such restriction
>   in a real editor.

You do not answer the question. I consider that indentation alone is not
enough to make the end of a block. It's not a question of editor and I
had some issues with vim as well because of that.

pass looks good to me to end a if block, continue is good to end a for
block and return is good to end a def block. If that's NOT good, just
tell me why and give me another solution to end a block who is not the
indentation because an indentation is not good enough for me to end a
block and it may trigger some problem when using different editors or
tools on the code.

>   Objects never are declared, at most names are declared.
>   /First/ learn a language, /then/ suggest changes.

Are all pythonist such pain in the ass or are you an exception ?

I've never suggesting to change the language, I'm asking if there is way
to do things. 

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Use of a variable in parent loop

2020-09-27 Thread Stephane Tougard via Python-list
On 2020-09-27, Chris Angelico  wrote:
> If you MUST use a block-end marker, try "# end" instead - at least
> then everyone *knows* it's nothing more than a comment.

Damn, you could not say that earlier !!!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Use of a variable in parent loop

2020-09-27 Thread Stephane Tougard via Python-list
On 2020-09-27, Stefan Ram  wrote:
>>Is there any other instruction to end a if than pass and ensure Emacs
>>does not break the indentation during a copy paste or an indent-region ?
>
>   We usually do not wish to tie our code to a defective editor.
>   I use vi, and can assure you that there is no such restriction
>   in a real editor.

It's funny, I've made a few tests and I see that pass has no impact on
if block in fact, I can put it anywhere and add code behind, it works
fine. I was sure that pass was breaking the if block, it does not.

That's however still the way Emacs seems to see it (I can not add 
any code in a if block after a pass, pass acts as if it breaks the if
block). 

As pass does nothing anyway, that looks like a good way to mark the end
of a block and I did not find any valid reason to not use it this way.
That's not a question of editor, that's a question of having a clear way
to mark the end of a block, I guess the Emacs maintener found this way
and I think it's a great idea.

If a extremist Pythonist takes over my code some day, he'll have to
search and delete hundreds of useless pass. I laugh already thinking
about it.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Use of a variable in parent loop

2020-09-27 Thread Stephane Tougard via Python-list
On 2020-09-27, Avi Gross  wrote:
> But when someone insists Python needs to
> change to meet their preconception, I get less sympathetic.

To clarify my question, I never asked that Python changes for me, I
asked if there was any way to change Python's behavior by using a module
or a configuration for example.

As "use strict;" in Perl or JS who changes the behavior of the language.

That's kind of difference between Perl and Python (or C and GO) is that
each Mongiste has its own style and uses Perl the way it fits for his
needs, while Pythonist has to write Python as it has been defined (this
rule is much stronger with GO).

To be frank, I don't really care the rules and supposed best practices,
I use a language the way it fits me. So I'll pass on the advices like
"we never use this like this" without more reason that "we just don't do
it" or "it's not expected to be done this way".

Anyway, thanks for your help.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Use of a variable in parent loop

2020-09-27 Thread Stephane Tougard via Python-list
On 2020-09-27, Terry Reedy  wrote:
> emacs with python-mode has been and likely still is used by some 
> experienced python programmers. I have never seen anyone but a rank 

Yes, since I discovered that an empty has almost the same effect than a
pass to end a block.

> The 'pass' line does not mark the end of the if block.

Yes, I know, I discovered that yesterday. Reading the documentation, it
should not anyway.

The way Emacs understands it is misleading.

> Python only has a temporary overlap mechnism:

That's the only answer I was expecting instead of all this arguing as if
I said any blasphem because I asked how can we change the behavior of
the language. 

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Use of a variable in parent loop

2020-09-27 Thread Stephane Tougard via Python-list
On 2020-09-27, Cameron Simpson  wrote:
>>In many non declarative language, if I do print($var), it just prints
>>and undefined value with returning an error.
>
> And that way lie MANY MANY bugs not detected until an undefined value 
> actually causes an issue, if that ever happens. In some languages 

Totally agree, it's not an acceptable behavior.

I would not do some Perl without 'use strict'
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Use of a variable in parent loop

2020-09-27 Thread Stephane Tougard via Python-list
On 2020-09-27, Chris Angelico  wrote:
> Or maybe Emacs *isn't* breaking it, and it's just an autoindentation
> thing. I don't know.

>From the discussion I read about this feature, it considers that 'pass' is
use to write an empty def()

def();
pass

So it's logic for it to indent one level up after a 'pass' because the people
who made it did not see any other usage to 'pass' than that.

if True:
pass
print("It's true")

The 'pass' is totally useless by itself, it can be replaced by a comment.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Use of a variable in parent loop

2020-09-27 Thread Stephane Tougard via Python-list
On 2020-09-28, MRAB  wrote:
> It's used where the language requires a statement.
>
> In, say, C, you would use empty braces:
>
>  while (process_next_item()) {
>  /* Do nothing. */
>  }

If I want to express nothing in C, I put nothing and it works fine.

#include 

int main(int argc, char * argv[])
{
  if(1 == 1)
;
  printf("Hello\n");
  return 0;
}

>  while process_next_item():
>  # Do nothing.
>  pass

while p():
# do nothing
continue

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Use of a variable in parent loop

2020-09-27 Thread Stephane Tougard via Python-list
On 2020-09-28, Manfred Lotz  wrote:
> On Mon, 28 Sep 2020 05:20:20 +0800
> Stephane Tougard  wrote:
>
>> On 2020-09-27, Manfred Lotz  wrote:
>> > - http://localhost:2015/tutorial/controlflow.html#pass-statements  
>> ...
>> > (In comparison to guys like ChrisA and StefanR and others here I am
>> > also a Python beginner)  
>> 
>> To give me a pointer on your localhost, I could guess.
>
> Don't understand this sentence.

The URL you gave is pointing to your localhost, your own computer if you
prefer.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Use of a variable in parent loop

2020-09-27 Thread Stephane Tougard via Python-list
On 2020-09-28, Cameron Simpson  wrote:
> That said, Stephane: I don't believe in "best practice" as _the_ best 
> practice, but I certainly believe there's "bad practice".

I kind of disagree with that, what I mean that there is no bad practice
to get the work done. There may be bad practice to write a code that you
intend to share or as part of a bigger project. Still, that depends how
you deliver your code.

For example, in Perl I sometime make extensive usage of goto(), through
this is usually considered bad practice I've read several documents who
stated otherwise.

Using goto() may make the code much simpler to understand when you
encounter a lot of error cases in a code.

The try: except: of Python, as I understand it, is never more than a
goto() in disguise (at least, that's the way I use goto() in Perl).

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Use of a variable in parent loop

2020-09-27 Thread Stephane Tougard via Python-list
On 2020-09-28, Mike Dewhirst  wrote:
> [1] If you live with Perl non-stop I agree Perl code can be read in
> future. But it requires allocation of serious brain-space for me at
> least to come back to it.

Let's be franc, I can read my own Perl code (very C-ish) without any
issue. I live with it since 20 years.

But I've seen some Perl code that is total gebbiresh to me, still doing
the job correctly.


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Use of a variable in parent loop

2020-09-28 Thread Stephane Tougard via Python-list
On 2020-09-27, Manfred Lotz  wrote:
> - http://localhost:2015/tutorial/controlflow.html#pass-statements
...
> (In comparison to guys like ChrisA and StefanR and others here I am also
> a Python beginner)

To give me a pointer on your localhost, I could guess.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Use of a variable in parent loop

2020-09-28 Thread Stephane Tougard via Python-list
On 2020-09-27, Grant Edwards  wrote:
> Maybe you need to choose different editors and tools.

In my world, humans don't adapt to tools but human adapt tools to their
needs.

> A guy I worked for many years ago used to write BASIC programs in C by
> using a bizarre set of pre-processor macros.  While it provided his
> employees with plenty of amusement, he could never get the programs to
> work right...

It's normal, he was an ass. When I manage a team, I don't enforce tools
or language, I ask them to work the best way they can to get the things
done. If they want to write C in Perl (as I often do), I'm happy. If
they prefer Ruby (that I never learnt), or Lisp ... as long as it works
and they are able to maintain it, I'm happy as well.

Nothing is more enjoyable than a platform running a variety of languages
and technologies, working all together.

And FYI, I've done this way since 25 years and I count a few good
success in my career. Practically, my way of doing things works is at least
as well as any.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Use of a variable in parent loop

2020-09-28 Thread Stephane Tougard via Python-list
On 2020-09-27, MRAB  wrote:
>> If a extremist Pythonist takes over my code some day, he'll have to
>> search and delete hundreds of useless pass. I laugh already thinking
>> about it.
> He could write some code to do it.

I would do it in Perl, LOL.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Use of a variable in parent loop

2020-09-28 Thread Stephane Tougard via Python-list
On 2020-09-27, Joe Pfeiffer  wrote:
> and so forth.  What I discovered in fairly short order was that it made
> it easier for me to read my own code, but did absolutely nothing for
> either me reading other people's code, nor for them reading mine.  I
> eventually concluded my best move was to just suck it up and learn to
> program in the language as intended.

Not that I disagree, but coming from twenty years of Perl, it means
where nobody really understands the code of anybody else, that never has
really been a concern to me.

However, I discovered that Emacs interprets as well an empty line or a
comment as a breaking point of a block, it's not as good as the use of
pass because I still have to indent up manually, but at least the
indent-region does not break it.

-- 
https://mail.python.org/mailman/listinfo/python-list