Re: Threading plus multiprocessing plus cv2 error

2020-08-30 Thread Karen Shaeffer via Python-list


> On Aug 29, 2020, at 10:12 PM, Stephane Tougard via Python-list 
>  wrote:
> 
> 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 ?
> 

Hello,
On linux, fork is a kernel system call. The linux kernel creates two identical 
processes running in separate memory spaces. At the time of creation, these 
memory spaces have the same content. There are some issues to be aware of. Just 
type ‘man fork’ on the command line of a linux system, and you can read about 
the issues of concern, presuming you have installed the manual pages for the 
linux kernel system calls.

If the forked process doesn’t overlay onto a separate memory space, then the 
fork system call fails, returning a failure code to the parent process. When 
the linux kernel is executing the fork system call, the parent (forking 
process) is blocked on the system call. The linux kernel actually takes over 
the parent process during execution of the system call, running that process in 
kernel mode during the execution of the fork process. The parent (forking) 
process only restarts, after the kernel returns.

On linux, within a given process, threads share the same memory space. If that 
process is the python interpreter, then the Global lock ensures only one thread 
is running when the fork happens. After the fork, then you have two distinct 
processes running in two separate memory spaces. And the fork man page 
discusses the details of concern with regards to specific kernel resources that 
could be referenced by those two distinct processes. The thread context is just 
a detail in that respect. All the threads of the parent process that forked the 
new process all share the same parent memory space.

humbly,
kls

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


Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-30 Thread Chris Green
Karsten Hilbert  wrote:
> > However the problem appears to be that internally in Python 3 mailbox
> > class there is an assumption that it's being given 'ascii'.
> 
> Do you really _need_ the mailbox class ? From what you've
> written so far my understanding was that you receive data
> (bytes) and want to append that to a file (which happens
> to be an mbox).
> 
> Can't you "just do that" ?
> 
> IOW, read the bytes, open the file, dump the bytes, close the file ?
> 
This would have been my next approach but see the new thread I've
started about this.  The fis was to change the read from stdin so that
it produced bytes instead of a string.  The bytes are fed into the
mailbox class and it no longer tries to decode them.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-30 Thread Chris Green
Cameron Simpson  wrote:
> On 29Aug2020 16:50, Chris Green  wrote:
> >However the problem appears to be that internally in Python 3 mailbox
> >class there is an assumption that it's being given 'ascii'.  Here's
> >the error (and I'm doing no processing of the message at all):-
> >
> >Traceback (most recent call last):
> >  File "/home/chris/.mutt/bin/filter.py", line 102, in 
> >mailLib.deliverMboxMsg(dest, msg, log)
> >  File "/home/chris/.mutt/bin/mailLib.py", line 52, in deliverMboxMsg
> >mbx.add(msg)
> [...]
> 
> Here is the entire save-to-mbox code form my own mailfiler:
> 
> text = M.as_string(True).replace('\nFrom ', '\n>From ')
> with open(folderpath, "a") as mboxfp:
>   mboxfp.write(text)
> 
> where M is the current message, a Message object.
> 
> Note that this does _not_ assume ASCII output. The process here is:
> 
> - transcribe the message to a Python 3 str (so Unicode code points)
> - replace embedded "From " to protect the mbox format
> - open the mbox for append - the _default_ encoding is utf-8
> - write the message in utf-8 because of the open mode
> 
> This sidesteps the library you're using which may well do something 
> ASCII based. And it has _never_ failed for me.
> 
Thanks Caneron, but I have now finally fixed my problem, see the new
thread.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Silly question, where is read() documented?

2020-08-30 Thread Chris Green
Terry Reedy  wrote:
> On 8/29/2020 12:18 PM, Chris Green wrote:
> > Well it sounds a silly question but I can't find the documentation for
> > read().  It's not a built-in function and it's not documented with
> > (for example) the file type object sys.stdin.
> 
> sys.stdin is of no particular type, but must at least have a .read method.
> 
> > So where is it documented?  :-)
> 
> >>> import sys; sys.stdin
> should give a hint.  In the standard REPL,
> 
> <_io.TextIOWrapper name='' mode='r' encoding='utf-8'>
> 
> As others said, actually look in the io module doc.  You might spend 
> some time reading the doc to get an idea of what is going on.  If you 
> run from IDLE, you currently get
> 
> 
> (I should make that more like the REPL answer.)
> 
Yes, quite! :-)

All I actually wanted to find out was the difference between what is
returned by sys.stdin.read() in Python 2 and Python 3 as that turned
out to be the fundamental cause of the mail handling problem I have
been airing in other threads here.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Where read() is documented

2020-08-30 Thread Chris Green
MRAB  wrote:
> On 2020-08-29 17:48, Chris Green wrote:
> > Stefan Ram  wrote:
> >> Chris Green  writes:I can't find the documentation for
> >> >read().  It's not a built-in function and it's not documented with
> >> >(for example) the file type object sys.stdin.
> >> 
> >> |read() (asyncio.StreamReader method), 894
> >> |read() (chunk.Chunk method), 1385
> >> |read() (codecs.StreamReader method), 164
> >> |read() (configparser.ConfigParser method), 537
> >> |read() (http.client.HTTPResponse method), 1276
> >> |read() (imaplib.IMAP4 method), 1291
> >> |read() (in module os), 578
> >> |read() (io.BufferedIOBase method), 622
> >> |read() (io.BufferedReader method), 625
> >> |read() (io.RawIOBase method), 621
> >> |read() (io.TextIOBase method), 626
> >> |read() (mimetypes.MimeTypes method), 1146
> >> |read() (mmap.mmap method), 1053
> >> |read() (ossaudiodev.oss_audio_device method), 1388
> >> |read() (ssl.MemoryBIO method), 1024
> >> |read() (ssl.SSLSocket method), 1005
> >> |read() (urllib.robotparser.RobotFileParser method), 1268
> >> |read() (zipfile.ZipFile method), 499
> >> Index of "The Python Library Reference, Release 3.9.0a3"
> >> 
> >> 
> > But none of those is the documentation for read(), they're just places
> > that refer to read().
> > 
> There's no read() function. What you're referring to are the 'read' 
> methods of various classes.
> 
Yes, OK, method rather than function.


> If you open a file in text mode, you'll get an instance of 
> TextIOWrapper, which inherits .read from TextIOBase.
> 
> If you open a file in binary mode, you'll get an instance of 
> BufferedReader, which has a .read method.
> 
> Multiple classes, each with its own 'read' method.
> 
> sys.stdin is an instance of TextIOWrapper, so for that you should look 
> at the methods of TextIOWrapper.

I went to sys.stdin but it didn't really lead me easily to the read()
method.  All I actually wanted to know was what was the type of the
return value of the read() method which is different in Python 2 and 3.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Threading plus multiprocessing plus cv2 error

2020-08-30 Thread John O'Hagan
On Sat, 29 Aug 2020 13:01:12 -0400
Dennis Lee Bieber  wrote:

> On Sat, 29 Aug 2020 18:24:10 +1000, John O'Hagan
>  declaimed the following:
> 
> >There's no error without the sleep(1), nor if the Process is started
> >before the Thread, nor if two Processes are used instead, nor if two
> >Threads are used instead. IOW the error only occurs if a Thread is
> >started first, and a Process is started a little later.
> >
> >Any ideas what might be causing the error?
> >  
> 
>   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).
> 
> https://stackoverflow.com/questions/54466572/how-to-properly-multithread-in-opencv-in-2019
> (which points to)
> https://answers.opencv.org/question/32415/thread-safe/?answer=32452#post-id-32452
> """
> The library itself is thread safe in that you can have multiple calls
> into the library at the same time, however the data is not always
> thread safe. """
> 
>   The sleep(1), when compounded with the overhead of starting
> the thread, and then starting the process, likely means the thread
> had exited before the process actually is started. Try replacing the
> sleep(2) in the work code with something like sleep(30) -- I
> hypothesize that you'll get the same error condition even with the
> sleep(1) in place.
> 
> 

Thanks for the reply. 

You're right, the error also happens with a longer sleep, or no sleep
at all, inside the function. That sleep is only there in the example to
keep the windows open long enough to see the images if they are
successfully displayed.

I could well be wrong as I'm not fully across multiprocessing, but I
think the Stackoverflow question and answer you linked above relate to a
different situation, with multithreaded cv2 operations on shared image
data. 

In my example, AFAIK (which is not very far) it shouldn't matter whether
the new process is sharing the thread, or whether the thread has
exited, because the thread and the process aren't using the same data.
Or (as is quite likely) am I misunderstanding your point?

Cheers

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


Problem running a FOR loop

2020-08-30 Thread Steve
Compiles, no syntax errors however, line 82 seems to run only once when the
FOR loop has completed.
Why is that?  All fields are to contain the specifications, not just the
last one.

Steve

--
ThisList = ["start"]

#===
def FillTheList():
   x=0
   ThisList = []
   with open("Specifications.txt", 'r') as infile:
 for lineEQN in infile: # loop to find each line in the file for that
dose
 if lineEQN[0:1] == "-":
   ListItem = lineEQN[1:6].strip()
   ThisList.append(ListItem)

   return(ThisList)

#

def EditDataByForm():

import tkinter as tk
from tkinter import ttk
import sys

window = tk.Tk()

window.title("Python Tkinter Text Box")
window.minsize(700,700) #height, width

#===
def GetLineByItem(DataType):  #get line by item in column 3 - 5
#print("DataType = " + DataType)
DataLetter = DataType[0:1]

if DataLetter.isupper(): # == "Specs":
FileToBeEdited = "Specifications.txt"
else:
FileToBeEdited = "DataSpecifications.txt"

with open(FileToBeEdited, 'r') as infile:
 for lineEQN in infile: # loop to find each line in the file for
that dose
   if ((lineEQN[1:2]== DataLetter)):
   A = lineEQN[1:46]# Whole Line
   a = lineEQN[34:46].strip()   # Just the Data
   # print("A = " + A )
   # print("a = " + a)
  
return(A, a)

#===

def ClickSubmit():
window.destroy()
#===

label = ttk.Label(window, text = "Enter the new readings")
label.grid(column = 1, row = 1)
 
ThisList = FillTheList()
x = 3  # Allows for two rows at the top of the form used for headers
y = 0  # Scans the datafile to fill the list

for lineItem in range(len(ThisList)):

 SpecLine, Spec = GetLineByItem(ThisList[y])
 OldSpec = Spec
 #print("OldSpec = " + OldSpec)
 NewSpec = " "

 SVRlabel = ttk.Label(window, text = SpecLine + "  "*5)
 SVRlabel.grid(column = 1, row = x)
 
 NewSpec = tk.StringVar()
 SVRCodeEntered = ttk.Entry(window, width = 15, textvariable =
NewSpec)
 SVRCodeEntered.grid(column = 2, row = x, pady = 15)

 print("x , y = " + str(x) + ", " + str(y))
 
 print("OldSpec2 = <" + OldSpec + "> ") #Use of <> show spaces if
any

 #81 The next line seems to run only once at the end of the FOR loop
<<
 SVRCodeEntered.insert(0, OldSpec)

 SVRCodeEntered.focus_set()

 x += 1 
 y += 1
#===
button = ttk.Button(window, text = "Submit", command = ClickSubmit)
button.grid(column= 2, row = 15)

window.mainloop()  
--
Specifications.txt.  This will align when using Notepad++.

A LTD Last Time Date  2020-08-29 00:55:18.610102   ##   
 B LDL Last Dose Line  2020-08-29 00:55:18.610102   ##   
 C LLL Last LTD line   2020-08-29 00:55:18.610102   ##   
 D LTD Last Time Date  2020-08-29 00:55:18.610102   ##   
 -
-E MSN Monitor Serial Number   JNGY263-T4464##   
 -
-F TSL TestStrip Lot Number45001 82990  ##   
-G SED Strip Expire Date   2021-05-31   ##   
 -
-H SSC Sensor Sequence Code71   ##   
-I SCN Sensor Code Number  G03  ##   
-J SSN Sensor Serial Number2021-01-31   ##   
-K SDE Sensor Date to Expire   2021-01-31   ##   
-L SDN Sensor Day Number   12##   
-M FDS First Date for Sensor   Fri Aug 17, 2020 09:34   ##
 -
-N IDT Insulin Dose Total  450  ##

 O DTD Data Time Date  Fri Aug 07, 2020 21:30   ##   
 P PTD Previous Time Date  Thu Nov 27, 1952 14:30   ##   
 -
 Q HL1 Half Life 1 1##

 R HL2 Half LIfe 2 2##   
 S HL3 Half Life 3 3##
 T TIL Total Insulin Layer 25   ##

---
Footnote:
The power company in 

Re: Threading plus multiprocessing plus cv2 error

2020-08-30 Thread Barry Scott



> On 29 Aug 2020, at 18:01, Dennis Lee Bieber  wrote:
> 
> On Sat, 29 Aug 2020 18:24:10 +1000, John O'Hagan 
> declaimed the following:
> 
>> There's no error without the sleep(1), nor if the Process is started
>> before the Thread, nor if two Processes are used instead, nor if two
>> Threads are used instead. IOW the error only occurs if a Thread is
>> started first, and a Process is started a little later.
>> 
>> Any ideas what might be causing the error?
>> 
> 
>   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).

In the parent you have 1 or more threads.

After fork the new process has 1 thread, which is not shared with the parent.
Any extra threads are not in the new process. But the memory in the new
process will have data structures from the parents other threads.

So no you never have two processes sharing an threads.

This leads to problems with locks.

Barry


> 
> https://stackoverflow.com/questions/54466572/how-to-properly-multithread-in-opencv-in-2019
> (which points to)
> https://answers.opencv.org/question/32415/thread-safe/?answer=32452#post-id-32452
> """
> The library itself is thread safe in that you can have multiple calls into
> the library at the same time, however the data is not always thread safe.
> """
> 
>   The sleep(1), when compounded with the overhead of starting the thread,
> and then starting the process, likely means the thread had exited before
> the process actually is started. Try replacing the sleep(2) in the work
> code with something like sleep(30) -- I hypothesize that you'll get the
> same error condition even with the sleep(1) in place.
> 
> 
> -- 
>   Wulfraed Dennis Lee Bieber AF6VN
>   [email protected]://wlfraed.microdiversity.freeddns.org/
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list
> 

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


Re: Problem running a FOR loop

2020-08-30 Thread Peter Otten
Steve wrote:

> Compiles, no syntax errors however, line 82 seems to run only once when
> the FOR loop has completed.
> Why is that?  All fields are to contain the specifications, not just the
> last one.

It seems that passing the StringVar to the Entry widget is not sufficient to 
keep it alive.

> for lineItem in range(len(ThisList)):

>  NewSpec = tk.StringVar()
>  SVRCodeEntered = ttk.Entry(window, width = 15, textvariable =
> NewSpec)

When the previous NewSpec is overwritten with the current one the previous 
gets garbage-collected and its value is lost. 

The straight-forward fix is to introduce a list:

  new_specs = []
> for lineItem in range(len(ThisList)):

>  NewSpec = tk.StringVar()
   new_specs.append(NewSpec)
>  SVRCodeEntered = ttk.Entry(window, width = 15, textvariable =
> NewSpec)

Another option is to store the StringVar as an attribute of the Entry:

> for lineItem in range(len(ThisList)):

>  NewSpec = tk.StringVar()
>  SVRCodeEntered = ttk.Entry(window, width = 15, textvariable =
> NewSpec)
   SVRCodeEntered.new_spec = NewSpec


-- 
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: Problem running a FOR loop

2020-08-30 Thread Steve
Yes, that first option worked.
Special thanks...
Steve
===

Footnote:
If 666 is considered evil, then technically, 25.8069758 is the root of all
evil.

-Original Message-
From: Python-list  On
Behalf Of Peter Otten
Sent: Sunday, August 30, 2020 5:29 AM
To: [email protected]
Subject: Re: Problem running a FOR loop

Steve wrote:

> Compiles, no syntax errors however, line 82 seems to run only once 
> when the FOR loop has completed.
> Why is that?  All fields are to contain the specifications, not just 
> the last one.

It seems that passing the StringVar to the Entry widget is not sufficient to
keep it alive.

> for lineItem in range(len(ThisList)):

>  NewSpec = tk.StringVar()
>  SVRCodeEntered = ttk.Entry(window, width = 15, textvariable =
> NewSpec)

When the previous NewSpec is overwritten with the current one the previous
gets garbage-collected and its value is lost. 

The straight-forward fix is to introduce a list:

  new_specs = []
> for lineItem in range(len(ThisList)):

>  NewSpec = tk.StringVar()
   new_specs.append(NewSpec)
>  SVRCodeEntered = ttk.Entry(window, width = 15, textvariable =
> NewSpec)

Another option is to store the StringVar as an attribute of the Entry:

> for lineItem in range(len(ThisList)):

>  NewSpec = tk.StringVar()
>  SVRCodeEntered = ttk.Entry(window, width = 15, textvariable =
> NewSpec)
   SVRCodeEntered.new_spec = NewSpec


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

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


How do I left-justify the information in the labels?

2020-08-30 Thread Steve
for lineItem in range(len(ThisList)):

 SpecLine, Spec = GetLineByItem(ThisList[y])
 OldSpec = Spec
 NewSpec = " "

 SVRlabel = ttk.Label(window, text = SpecLine + "  "*5)
 SVRlabel.grid(column = 1, row = x)
 
 NewSpec = tk.StringVar()
 New_Specs.append(NewSpec)
 SVRCodeEntered = ttk.Entry(window, width = 15, textvariable =
NewSpec)
 SVRCodeEntered.grid(column = 2, row = x, pady = 15)
 SVRCodeEntered.insert(0, OldSpec)
 x += 1 
 y += 1

Steve



Footnote:
Some mornings it just isn't worth chewing through the leather straps.

- 

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


Re: Where read() is documented

2020-08-30 Thread Chris Green
Stefan Ram  wrote:
> Chris Green  writes:
> >I went to sys.stdin but it didn't really lead me easily to the read()
> >method.  All I actually wanted to know was what was the type of the
> >return value of the read() method which is different in Python 2 and 3.
> 
> |>>> import sys
> |>>> >>> sys.stdin.read
> 
> |>>> help(sys.stdin.read)
> |Help on built-in function read:
> |
> |read(size=-1, /) method of _io.TextIOWrapper instance
> |Read at most n characters from stream.
> |
> |Read from underlying buffer until we have n characters or we hit EOF.
> |If n is negative or omitted, read until EOF.
> |
> |>>> type(sys.stdin.read())
> |^Z
> |
> 
>   Note that above it's called a "method" twice and once
>   a "function".
> 
>   (If I would have written the body of the documentation,
>   I'd use "size" instead of "n" and clearly separate 
>   effects and results, e.g.,
> 
> |EFFECTS
> |
> |If  is not negative, read from underlying buffer until
> | characters are read or until EOF was read. If 
> |is negative or omitted, read until EOF.
> |
> |RESULT
> |
> |The string read, type str, excluding a possible EOF read.
> 
Yes, I must admit I tend to forget about the 'built-in' documentation
that Python has.  Coming from assembler, C and C++ one doesn't expect
it, so I'm afraid I tend to search the on-line Python documentation.
Usually I find what I want but in this particular case I didn't.  I
must remember the interactive prompt!

Thanks.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Threading plus multiprocessing plus cv2 error

2020-08-30 Thread Barry


> On 30 Aug 2020, at 11:03, Stephane Tougard via Python-list 
>  wrote:
> 
> 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.

No. See https://www.man7.org/linux/man-pages/man2/fork.2.html which says:

“ Note the following further points:

   *  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
  this can cause.”

Barry
> 
> 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
> 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do I left-justify the information in the labels?

2020-08-30 Thread Peter Otten
Steve wrote:

> How do I left-justify the information in the labels?

>  SVRlabel = ttk.Label(window, text = SpecLine + "  "*5)
>  SVRlabel.grid(column = 1, row = x)

The text in the labels already is left-justified -- but the labels 
themselves are centered inside the grid cells.

You can change that with

label = ttk.Label(window, text=SpecLine)
label.grid(column=1, row=x, sticky=tkinter.W)  # W for "west"

See https://tkdocs.com/shipman/grid.html.

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


RE: How do I left-justify the information in the labels?

2020-08-30 Thread Steve
It turned out to be "sticky=tk.W" instead of "sticky=tkinter.w"
Probably because I have   "import tkinter as tk"
It does work though.

Mischief Managed
Steve


FootNote:
If money does not grow on trees, then why do banks have branches?

-Original Message-
From: Python-list  On
Behalf Of Peter Otten
Sent: Sunday, August 30, 2020 10:32 AM
To: [email protected]
Subject: Re: How do I left-justify the information in the labels?

Steve wrote:

> How do I left-justify the information in the labels?

>  SVRlabel = ttk.Label(window, text = SpecLine + "  "*5)
>  SVRlabel.grid(column = 1, row = x)

The text in the labels already is left-justified -- but the labels
themselves are centered inside the grid cells.

You can change that with

label = ttk.Label(window, text=SpecLine) label.grid(column=1, row=x,
sticky=tkinter.W)  # W for "west"

See https://tkdocs.com/shipman/grid.html.

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

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


Re: Video file to subtitles file

2020-08-30 Thread MRAB

On 2020-08-30 07:23, Muskan Sanghai wrote:

On Sunday, August 30, 2020 at 11:46:15 AM UTC+5:30, Chris Angelico wrote:
On Sun, Aug 30, 2020 at 4:11 PM Muskan Sanghai  wrote: 
> 
> On Sunday, August 30, 2020 at 10:57:00 AM UTC+5:30, Christian Gollwitzer wrote: 
> > Am 29.08.20 um 13:51 schrieb Muskan Sanghai: 
> > > I want to extract subtitles from a MPEG video (which does not have any previous subtitles) 
> > I'm still not sure I get it. "Extract" subtitles, when they are NOT 
> > there? Can it be, by any chance, that you are talking about speech 
> > recognition? I.e., you want a software which understands the spoken word 
> > in the movie sound and turns that into text, which can be shown as 
> > subtitles? Like the "auto-generated" subtitles which youtube offers for 
> > some videos. 
> > 
> > If so, it is a complex task and will not work overly well. I defer to 
> > the experts if there are any usable speech recognitino engines for this 
> > task. 
> > 
> > Christian 
> Yes, this is what I exactly want to do. I want to create a software which understands the spoken word in the movie sound and turns that into text. 
>
I recommend looking into CMU Sphinx then. I've used that from Python. 

The results are highly entertaining. 


ChrisA

Okay I will try it, thank you.

Speech recognition works best when there's a single voice, speaking 
clearly, with little or no background noise. Movies tend not to be like 
that.


Which is why the results are "highly entertaining"...
--
https://mail.python.org/mailman/listinfo/python-list


Re: Video file to subtitles file

2020-08-30 Thread Christian Gollwitzer

Am 30.08.20 um 17:25 schrieb MRAB:

On 2020-08-30 07:23, Muskan Sanghai wrote:

On Sunday, August 30, 2020 at 11:46:15 AM UTC+5:30, Chris Angelico wrote:

I recommend looking into CMU Sphinx then. I've used that from Python.
The results are highly entertaining.
ChrisA

Okay I will try it, thank you.

Speech recognition works best when there's a single voice, speaking 
clearly, with little or no background noise. Movies tend not to be like 
that.


Which is why the results are "highly entertaining"...



Well, with enough effort it is possible to build a system that is more 
useful than "entertaining". Google did that, English youtube videos can 
be annotated with subtitles from speech recognition. For example, try 
this video:

https://www.youtube.com/watch?v=lYVLpC_8SQE

Go to the settings thing (the little gear icon in the nav bar) and 
switch on subtitles, English autogenerated. You'll see a word-by-word 
transcription of the text, and most of it is accurate.


There are strong arguments that anything one can build with open source 
tools will be inferior. 1) They'll probably have a bunch of highly 
qualified KI experts working on this thing 2) They have an enormous 
corpus of training data. Many videos already have user-provided 
subtitles. They can feed all of this into the training.


I'm waiting to be disproven on this point ;)

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


How do I pull the updated information from a tkinter form?

2020-08-30 Thread Steve
#  With this program, I can read the information from
#  Specifications.txt file and display it on a form.
#  The user can then update/modify the fields. This is
#  all working fine and beeautifully...
#  
#  I now need to reverse the process and replace the
#  adjusted lines of data back into the Specifications.txt
#  file.  Fortunately, that code has already been
#  written .

#  What I cannot seem to do is to pull the adjusted
#  information from the form into variables, or a
#  list/array, so that can be used for the update to the file.

#  Suggestions for what to look up to study this
#  through will help.
#
#  Thank you
#  Steve
# ---

import tkinter as tk
from tkinter import ttk
import sys

ThisList = ["start"]

#===
def FillTheList():
   x=0
   ThisList = []
   with open("Specifications.txt", 'r') as infile:
 for lineEQN in infile: # loop to find each line in the file for that
dose
 if lineEQN[0:1] == "-": # Lines with "-" in space 1 have special
recognition for this form
   ListItem = lineEQN[1:6].strip() # Remove any spaces before and
after
   ThisList.append(ListItem) #Add the ListItem to ThisList
   return(ThisList)

#

def EditDataByForm():
window = tk.Tk()
window.title("Python Tkinter Text Box")
window.minsize(700,700) #height, width

#===
def GetLineByItem(DataType):  #get line by item in column 3 - 5
#print("DataType = " + DataType)
DataLetter = DataType[0:1] #Capture item letter ID for file check

if DataLetter.isupper(): # == "Specs":
FileToBeEdited = "Specifications.txt"
else:
FileToBeEdited = "DataSpecifications.txt"

with open(FileToBeEdited, 'r') as infile:
 for lineEQN in infile: # loop to find each line in the file for
that dose
   if ((lineEQN[1:2]== DataLetter)):
   A = lineEQN[1:46]# Whole Line
   a = lineEQN[34:46].strip()   # Just the Data
   # print("A = " + A )
   # print("a = " + a)
  
return(A, a) #Return the line and Data separately

#===
def ClickSubmit():
window.destroy()
#===

label = ttk.Label(window, text = "Enter the new readings")
label.grid(column = 1, row = 1)
 
ThisList = FillTheList()
x = 3  # Allows for two rows at the top of the form used for headers
y = 0  # Scans the datafile to fill the list

New_Specs = []
#SpecsToUpdate = []

for lineItem in range(len(ThisList)):

 SpecLine, Spec = GetLineByItem(ThisList[y])
 OldSpec = Spec
 NewSpec = " "

 SVRlabel = ttk.Label(window, text = SpecLine + "  "*5)
 SVRlabel.grid(column = 1, row = x,  sticky=tk.W)

 NewSpec = tk.StringVar()
 New_Specs.append(NewSpec)
 SVRCodeEntered = ttk.Entry(window, width = 15, textvariable =
NewSpec)
 
 SVRCodeEntered.grid(column = 2, row = x, pady = 15, sticky=tk.W)
 SVRCodeEntered.insert(0, OldSpec)
 x += 1 
 y += 1

#===
button = ttk.Button(window, text = "Submit", command = ClickSubmit)
button.grid(column= 2, row = 15)
window.mainloop()  
#===

EditDataByForm()
print ("Done")
#  Code needed to pull the updated fields from the form
#  as variables or in a list/array.  Once I have that, the code to replace 
#  code in the specifications.txt file has already been written.

#  Here is a sample of the Specifications.txt file:

---
-E MSN Monitor Serial Number   JNGY263-T4464##   
 -
-F TSL TestStrip Lot Number45001 82990  ##   
-G SED Strip Expire Date   2021-05-31   ##   
 -
-H SSC Sensor Sequence Code71   ##   
-I SCN Sensor Code Number  G03  ##   
-J SSN Sensor Serial Number2021-01-31   ##   
-K SDE Sensor Date to Expire   2021-01-31   ##   
-L SDN Sensor Day Number   12##   
-M FDS First Date for Sensor   Fri Aug 17, 2020 09:34   ##
 -
-N IDT Insulin Dose Total  450  ##



Foot

Re: How do I pull the updated information from a tkinter form?

2020-08-30 Thread Peter Otten
Steve wrote:

> #What I cannot seem to do is to pull the adjusted
> #information from the form into variables, or a
> #list/array, so that can be used for the update to the file.

The updated data is in the StringVar-s, which, fortunately, you have 
available in a list ;)

So:

> def EditDataByForm():
[...]
> window.mainloop()  
  return [spec.get() for spec in New_Specs]

  print(EditDataByForm())
> print ("Done")


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


RE: How do I pull the updated information from a tkinter form?

2020-08-30 Thread Steve
OK, I was closer than I thought.

Two weeks ago, the concept of tkinter and these forms were totally new to me
as well as, about  two days ago, python list was totally new too. I somehow
thought that "window.mainloop()" was supposed to be the last entry in the
function, silly me...
I did not think of returning the list.

Thank you, now it is back for another 30 hours of continuous programming...
(:
Steve


Footnote:
"What rhymes with orange?"
"No it doesn't.."

-Original Message-
From: Python-list  On
Behalf Of Peter Otten
Sent: Sunday, August 30, 2020 1:55 PM
To: [email protected]
Subject: Re: How do I pull the updated information from a tkinter form?

Steve wrote:

> #What I cannot seem to do is to pull the adjusted #information from 
> the form into variables, or a #list/array, so that can be used for the 
> update to the file.

The updated data is in the StringVar-s, which, fortunately, you have
available in a list ;)

So:

> def EditDataByForm():
[...]
> window.mainloop()
  return [spec.get() for spec in New_Specs]

  print(EditDataByForm())
> print ("Done")


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

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


Re: Video file to subtitles file

2020-08-30 Thread Chris Angelico
On Mon, Aug 31, 2020 at 3:16 AM Christian Gollwitzer  wrote:
>
> Am 30.08.20 um 17:25 schrieb MRAB:
> > On 2020-08-30 07:23, Muskan Sanghai wrote:
> >> On Sunday, August 30, 2020 at 11:46:15 AM UTC+5:30, Chris Angelico wrote:
> >>> I recommend looking into CMU Sphinx then. I've used that from Python.
> >>> The results are highly entertaining.
> >>> ChrisA
> >> Okay I will try it, thank you.
> >>
> > Speech recognition works best when there's a single voice, speaking
> > clearly, with little or no background noise. Movies tend not to be like
> > that.
> >
> > Which is why the results are "highly entertaining"...
>
>
> Well, with enough effort it is possible to build a system that is more
> useful than "entertaining". Google did that, English youtube videos can
> be annotated with subtitles from speech recognition. For example, try
> this video:
> https://www.youtube.com/watch?v=lYVLpC_8SQE
>
> Go to the settings thing (the little gear icon in the nav bar) and
> switch on subtitles, English autogenerated. You'll see a word-by-word
> transcription of the text, and most of it is accurate.
>
> There are strong arguments that anything one can build with open source
> tools will be inferior. 1) They'll probably have a bunch of highly
> qualified KI experts working on this thing 2) They have an enormous
> corpus of training data. Many videos already have user-provided
> subtitles. They can feed all of this into the training.
>
> I'm waiting to be disproven on this point ;)
>

The OP doesn't want to use Google's services for this. That doesn't
disprove your point, but... :)

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


Re: Video file to subtitles file

2020-08-30 Thread MRAB

On 2020-08-30 18:10, Christian Gollwitzer wrote:

Am 30.08.20 um 17:25 schrieb MRAB:

On 2020-08-30 07:23, Muskan Sanghai wrote:

On Sunday, August 30, 2020 at 11:46:15 AM UTC+5:30, Chris Angelico wrote:

I recommend looking into CMU Sphinx then. I've used that from Python.
The results are highly entertaining.
ChrisA

Okay I will try it, thank you.

Speech recognition works best when there's a single voice, speaking 
clearly, with little or no background noise. Movies tend not to be like 
that.


Which is why the results are "highly entertaining"...



Well, with enough effort it is possible to build a system that is more
useful than "entertaining". Google did that, English youtube videos can
be annotated with subtitles from speech recognition. For example, try
this video:
https://www.youtube.com/watch?v=lYVLpC_8SQE

Go to the settings thing (the little gear icon in the nav bar) and
switch on subtitles, English autogenerated. You'll see a word-by-word
transcription of the text, and most of it is accurate.


There's not much background noise there; it takes place in a quiet room.


There are strong arguments that anything one can build with open source
tools will be inferior. 1) They'll probably have a bunch of highly
qualified KI experts working on this thing 2) They have an enormous
corpus of training data. Many videos already have user-provided
subtitles. They can feed all of this into the training.

I'm waiting to be disproven on this point ;)


--
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


Re: Symlinks already present

2020-08-30 Thread Cameron Simpson
On 27Jul2020 22:19, Grant Edwards  wrote:
>On 2020-07-27, Termoregolato  wrote:
>> Il 26/07/20 22:47, dn ha scritto:
>>> Thus, compare the results of the two calls to detect a difference.
>>
>> I will try also another way, If I don't err symlinks and original
>> directory  have the same inode number (I talk about Linux, where I'm
>> using the application).
>
>You err.  Symlinks are distinct i-nodes which are not the same i-node
>as the destination.  A symlink is basically a file containing a string
>that is read and then used a path to another file.

We need to be careful with terminology (just for clarity).

Each "source" symlink has its own inode. But if you os.stat() the 
symlink it follows the symlink and you get the inode for the "target" 
directory - two symlinks which point at the same directory will return the same 
inode and thus (st_dev,st_ino) in that stat result.

That can be used for comparison, and you don't need to readlink or 
anything like that - let the OS do it all for you during the os.stat() 
call.

>If you create a "hard" link (ln without the '-s') then you end up a single
>i-node that has entries in multiple directories.

Aye.

>[old-Unix-guy story: Way back when, SunOS used to allow you (if root)
>to create a hard link to a directory.  It's not something you did a
>second time.]

It's a well defined operation. There are some policy choices an OS can 
make about some of the side effects (how does pwd work? how you got 
there? or some underlying "real" path - this spills over into "what does 
".." mean?), etc. But having made those choices, the idea is just fine.

As a counter example, many rsync based backup systems have the following 
underlying approach:

- make a new directory tree with every file hardlinked from the previous 
  backup tree

- rsync into the new tree, because rsync unlinks and replaces changed 
  files

By contrast, MacOS Time Machine utilitises hardlinking directories on 
HFS volumes: instead of making a new directory tree full of hardlinks 
you just hardlink the top directory itself if nothing inside it has been 
changed.

Cheers,
Cameron Simpson 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Symlinks already present

2020-08-30 Thread Cameron Simpson
On 27Jul2020 20:20, Termoregolato  wrote:
>Il 26/07/20 20:39, Dennis Lee Bieber ha scritto:
>>Since symbolic links are essentially just short files containing the
>>path to the eventual target file/directory, with an OS flag that the file
>>is a link
>
>Yes, I use them massively to give to a lot of directories a kind of 
>order, depending on their contents. It's simple to see if link is 
>broken, but not if they're duplicate

Hmm. If you're scanning them all, you can at least cache the (dev,ino) 
of the link target. So broken is stat-failed. Duplicate is 
seen-this-(dev,ino)-before. You only need the stat, not to (for example) 
resolve the path the symlink becomes.

You've probably thought of this already of cource.

Cheers,
Cameron Simpson 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Symlinks already present

2020-08-30 Thread Chris Angelico
On Mon, Aug 31, 2020 at 1:17 PM Cameron Simpson  wrote:
> Each "source" symlink has its own inode. But if you os.stat() the
> symlink it follows the symlink and you get the inode for the "target"
> directory - two symlinks which point at the same directory will return the 
> same
> inode and thus (st_dev,st_ino) in that stat result.
>
> That can be used for comparison, and you don't need to readlink or
> anything like that - let the OS do it all for you during the os.stat()
> call.

Note that this is only the case if os.stat is called with
follow_symlinks=True, which is the default, but isn't the only way to
do things. And if you get stat results while you're iterating over a
directory, you don't follow symlinks.

> >[old-Unix-guy story: Way back when, SunOS used to allow you (if root)
> >to create a hard link to a directory.  It's not something you did a
> >second time.]
>
> It's a well defined operation. There are some policy choices an OS can
> make about some of the side effects (how does pwd work? how you got
> there? or some underlying "real" path - this spills over into "what does
> ".." mean?), etc. But having made those choices, the idea is just fine.

Is it well defined? Because of the ".." issue, it's not going to be as
symmetric as hardlinking files is. You can move a file by hardlinking
it and then unlinking the original name. If you do that with a
directory, at what point do you update its parent pointer? What
happens if you create TWO more hardlinks, and then unlink the original
name? Can you even *have* a single concept of a "real path" without it
basically just being symlinks in disguise?

BTW, the pwd issue actually isn't an issue, since it really *will* be
"how you got there". You can see that with modern systems if you have
symlinks in the path, or rename a directory:

rosuav@sikorsky:~/tmp$ mkdir -p a/b/c/d/e
rosuav@sikorsky:~/tmp$ cd a/b/c/d/e
rosuav@sikorsky:~/tmp/a/b/c/d/e$ mv ~/tmp/a/{b,q}
rosuav@sikorsky:~/tmp/a/b/c/d/e$ pwd
/home/rosuav/tmp/a/b/c/d/e
rosuav@sikorsky:~/tmp/a/b/c/d/e$ cd `pwd`
bash: cd: /home/rosuav/tmp/a/b/c/d/e: No such file or directory
rosuav@sikorsky:~/tmp/a/b/c/d/e$ ls -al
total 8
drwxr-xr-x 2 rosuav rosuav 4096 Aug 31 14:17 .
drwxr-xr-x 3 rosuav rosuav 4096 Aug 31 14:17 ..
rosuav@sikorsky:~/tmp/a/b/c/d/e$ cd ..
rosuav@sikorsky:~/tmp/a/q/c/d$ pwd
/home/rosuav/tmp/a/q/c/d
rosuav@sikorsky:~/tmp/a/q/c/d$

As soon as I try to go to the parent, it has to figure out what the
real path to that parent is. Otherwise, it's just the path that I
typed to get there - even though that might no longer be correct.
(There have been times, for instance, when I'm in a "dead" directory
and have to cd `pwd` to get back to the "real" directory with the same
name.)

The parent directory is crucially important here.

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


Re: Video file to subtitles file

2020-08-30 Thread Christian Gollwitzer

Am 30.08.20 um 21:43 schrieb MRAB:

On 2020-08-30 18:10, Christian Gollwitzer wrote:

Well, with enough effort it is possible to build a system that is more
useful than "entertaining". Google did that, English youtube videos can
be annotated with subtitles from speech recognition. For example, try
this video:
https://www.youtube.com/watch?v=lYVLpC_8SQE



There's not much background noise there; it takes place in a quiet room.


 It becomes a bit worse once the background music sets in, but still is 
usable. Feel free to try any other video. I think, it works with any 
video in English.


I think that for "Hollywood"-style movies you will always have a crisp 
sound of the speech. They want the viewers to listen effortlessly - 
background music is typical, "true" noise is rare.


Maybe try with this video:
https://www.youtube.com/watch?v=nHn4XpKA6vM

As soon as they are up in the air you have the engine sound overlaying 
the speech, and still the transcription is quite good. It sometimes 
mistakes the flapping of the engine as "applause" and misses a word or a 
sentence, but still very good.


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


Re: Video file to subtitles file

2020-08-30 Thread Chris Angelico
On Mon, Aug 31, 2020 at 3:36 PM Christian Gollwitzer  wrote:
>
> Am 30.08.20 um 21:43 schrieb MRAB:
> > On 2020-08-30 18:10, Christian Gollwitzer wrote:
> >> Well, with enough effort it is possible to build a system that is more
> >> useful than "entertaining". Google did that, English youtube videos can
> >> be annotated with subtitles from speech recognition. For example, try
> >> this video:
> >> https://www.youtube.com/watch?v=lYVLpC_8SQE
> >>
> >>
> > There's not much background noise there; it takes place in a quiet room.
>
>   It becomes a bit worse once the background music sets in, but still is
> usable. Feel free to try any other video. I think, it works with any
> video in English.
>
> I think that for "Hollywood"-style movies you will always have a crisp
> sound of the speech. They want the viewers to listen effortlessly -
> background music is typical, "true" noise is rare.
>
> Maybe try with this video:
> https://www.youtube.com/watch?v=nHn4XpKA6vM
>
> As soon as they are up in the air you have the engine sound overlaying
> the speech, and still the transcription is quite good. It sometimes
> mistakes the flapping of the engine as "applause" and misses a word or a
> sentence, but still very good.
>

But remember, the OP specifically does NOT want to use Google or
Amazon services for this. What you're showcasing here has been trained
on the gigantic corpus of Youtube videos, and that's simply not going
to be practical to recreate. When I said the results were
"entertaining", I was talking about what CMU Sphinx is capable of
without any assistance (and also what I've seen from numerous
real-time captioning tools across the internet). Sometimes it's
reasonable... sometimes it just isn't.

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