Re: [Tutor] Getting a Process.start() error pickle.PicklingError: Can't pickle : it's not found as __builtin__.module with Python 2.7

2024-09-03 Thread marc nicole via Python-list
Hello Alan,

Thanks for the reply, Here's the code I tested for the debug:

import time
from multiprocessing import Process

def do_Something():
print('hello world!')

def start(fn):
   p = Process(target=fn, args=())
   p.start()

def ghello():
print ("hello world g")

def fhello():
print('hello world f')

if __name__ == "__main__":
start(do_something)
print("executed")
exit(0)

but neither "Hello World" or "Executed" are displayed in the console which
finishes normally without returning any message.

Module naming is OK and don't think it is a problem related to that.

Now the question, when to use Process/Multiprocess and when to use
Threading in Python?.Thread is there a distinctive use case that can
showcase when to use either? are they interchangeable? to note that using
Threading the console DID display the messages correctly!

Thanks.

Le mar. 3 sept. 2024 à 10:48, Alan Gauld via Tutor  a
écrit :

> On 02/09/2024 15:00, marc nicole via Python-list wrote:
> > Hello,
> >
> > I am using Python 2.7 on Windows 10
>
> Others have pointed out that 2.7 is unsupported and has
> been for many years now. Its also inferior in most
> respects including its error reporting.
> If possible you should upgrade to 3.X
>
> > from multiprocessing import Process
> > def do_something(text):
> > print(text)
> > if __name__ == "__main__":
> > q = Process(target=do_something,args=("somecmd") )
> > q.start()
> > # following code should execute right after the q.start() call
>
> So what does happen? If you put a print statement here does it execute
> before or after the error message? It might make things easier to
> debug(clearer error traceback) if you put the code to create the thread
> into a separate function?
>
> def do_Something(text)...
>
> def start(fn):
>q = Process
>q.start()
>
> if __name_
>start(do_something)
>print('Something here')
>
>
> > But getting the error at the call of Process().start():
> > pickle.PicklingError: Can't pickle : it's not found as
> > __builtin__.module
>
> But please show us the full error trace even if its not much.
>
> Also check your module naming, is there a possibility
> you've named your file do_something.py or similar?
> (I'm guessing the function is what is being pickled?)
>
> > anybody could provide an alternative to call the function do_something()
> in
> > a separate thread ?
>
> Why not just use the Threading module?
> If it's as simple as just running something in a
> thread multiprocessing is probably not needed.
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
>
>
> ___
> Tutor maillist  -  tu...@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python told me a Joke

2024-09-03 Thread Mild Shock via Python-list

You can try:

>>> 1,2 == 2,2
(1, True, 2)

Its the same as:

>>> 1, (2 == 2), 2
(1, True, 2)

Hope this helps!

Alan Bawden schrieb:

 Python 3.10.5 (v3.10.5:f37715, Jul 10 2022, 00:26:17) [GCC 4.9.2] on linux
 Type "help", "copyright", "credits" or "license" for more information.
 >>> x,_,z = [1,2,3]

Works as expected.

Now I didn't expect the following to work (but Python sometimes
surprises me!), so I tried:
  
 >>> x,2,z = [1,2,3]

   File "", line 1
 x,2,z = [1,2,3]
 ^^^
 SyntaxError: invalid syntax. Maybe you meant '==' or ':=' instead of '='?

Yeah, that makes sense, no surprises today...  Except "maybe you meant
'=='..." caught my attention.  _Could_ that be what someone would want
in this situation I wondered?  So I tried:

 >>> x,2,z == [1,2,3]
 (1, 2, False)

Now that made me laugh.

- Alan

[ Some people reading this will be tempted to explain what's really
   going on here -- it's not hard to understand.  But please remember that
   a joke is never funny if you have to explain it. ]



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


Python told me a Joke

2024-09-03 Thread Alan Bawden via Python-list
Python 3.10.5 (v3.10.5:f37715, Jul 10 2022, 00:26:17) [GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> x,_,z = [1,2,3]

Works as expected.

Now I didn't expect the following to work (but Python sometimes
surprises me!), so I tried:
 
>>> x,2,z = [1,2,3]
  File "", line 1
x,2,z = [1,2,3]
^^^
SyntaxError: invalid syntax. Maybe you meant '==' or ':=' instead of '='?

Yeah, that makes sense, no surprises today...  Except "maybe you meant
'=='..." caught my attention.  _Could_ that be what someone would want
in this situation I wondered?  So I tried:

>>> x,2,z == [1,2,3]
(1, 2, False)

Now that made me laugh.

- Alan

[ Some people reading this will be tempted to explain what's really
  going on here -- it's not hard to understand.  But please remember that
  a joke is never funny if you have to explain it. ]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Getting a Process.start() error pickle.PicklingError: Can't pickle : it's not found as __builtin__.module with Python 2.7

2024-09-03 Thread geodandw via Python-list

On 9/2/24 11:36, Barry Scott wrote:




On 2 Sep 2024, at 15:00, marc nicole via Python-list  
wrote:

I am using Python 2.7 on Windows 10


Why? Install Python 3.12 and it will be easier to get help and support.
If you have legacy that still needs porting then you can install 3.12 along side
the unsupported 3.12.


Barry


I think you mean alongside the unsupported 2.7.
--
https://mail.python.org/mailman/listinfo/python-list


Synchronise annotations -> docstring

2024-09-03 Thread Albert-Jan Roskam via Python-list
   Hi,
   Are there any tools that check whether type annotations and Numpydoc
   strings are consistent?
   I did find this Vim
   plugin: https://lxyuan0420.github.io/posts/til-vim-pydocstring-plugin.
   Looks incredibly useful, but I haven't tried it yet.
   Thanks!
   AJ
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Process.start

2024-09-03 Thread Keith Thompson via Python-list
r...@zedat.fu-berlin.de (Stefan Ram) writes:
> marc nicole  wrote or quoted:
>>Thanks for the reply, Here's the code I tested for the debug:
>>print("executed")
>>but neither "Hello World" or "Executed" are displayed in the console which
>
>   It shouldn't spit out "Executed" 'cause there's a lowercase
>   "e" in the mix. Talk about sweating the small stuff! 
>
>   That 'if __name__ == "__main__"' jazz? It's barking up the wrong
>   tree here, just muddying the waters. I'd 86 that clause for now.
>
>   In your start() function call, you're rockin' "do_something()",
>   but the actual function's defined as "do_Something()" with a
>   capital "S". Python's all about that case sensitivity.
>
>   Dropping that "exit(0)" bomb right after firing up the process?
>   That's like bailing on a gnarly wave before you even catch it.
>   It might pull the plug on the main process before the kid process
>   has a chance to strut its stuff.
>
>   Those "ghello" and "fhello" functions? They're just chillin'
>   there, not pulling their weight!
[...]

Stefan, you've recently started using a lot of slang in your posts.
I suggest that this is counterproductive.  For me, it makes your
posts more difficult to read.  I can imagine that it would be even
more difficult for readers whose first language is not English.

You also indent your own new text, which is exactly the opposite of
common Usenet conventions.  (You've been doing this for a long time.)

Please consider prioritizing your readers' convenience over whatever
benefit you derive from your unconventional posting style.

-- 
Keith Thompson (The_Other_Keith) keith.s.thompso...@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */
-- 
https://mail.python.org/mailman/listinfo/python-list


Trouble with mocking

2024-09-03 Thread Norman Robins via Python-list
I'm somewhat new to mocking for unit tests.

I have some code like this:

In foo/bar/baz.py I have 2 function I want to mock, one calls the other"
def function1_to_mock():
   .
   .
   .

def function2_to_mock():
   function1_to_mock()

In foo/bar/main.py I import 1 of these and call it"
from .baz import function2_to_mock

def some_function():
function1_to_mock()
.
.
.

I want to mock both function1_to_mock and function2_to_mock

In my test I do this:

def function1_to_mock(kid):
return MOCKED_VALUE

@pytest.fixture(autouse=True)
def mock_dependencies():
with patch(foo.bar.baz.function1_to_mock') as mock_function1_to_mock, \
 patch('foo.bar.main.function2_to_mock') as mock_function2_to_mock:
mock_function2_to_mock.return_value = {
'this': 'that
}
yield mock_function1_to_mock, mock_function2_to_mock

def test_main(mock_dependencies):
some_function()

When some_function is called the real function1_to_mock is called instead
of my mock.

Can someone please let me know how to properly mock these 2 functions.

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


RE: [Tutor] Getting a Process.start() error pickle.PicklingError: Can't pickle : it's not found as __builtin__.module with Python 2.7

2024-09-03 Thread AVI GROSS via Python-list
Unfortunately, Alan, even though 2.7 was considered pickled, people keep
taking it back out of the bottle and wondering why it does not work so well!

There are companies like Microsoft and Samsung that let people know their OS
on their devices will no longer be supported with updates and some apps may
no longer work if downloaded. And, yet, I bet for years afterwards, people
will refuse to upgrade because they don't want to replace equipment or even
learn a new slightly different interface.

Having said that, I understand many people are stuck for various reasons and
are required to use whatever version is officially allowed. For some
questions, answers may still be provided. There are some workarounds or even
newer packages designed to do what is not otherwise available.

But many of us here may not be answering the questions as we have no reason
to be able to access the old software or interest.

-Original Message-
From: Tutor  On Behalf Of
Alan Gauld via Tutor
Sent: Tuesday, September 3, 2024 4:41 AM
To: tu...@python.org
Cc: python-list@python.org
Subject: Re: [Tutor] Getting a Process.start() error pickle.PicklingError:
Can't pickle : it's not found as __builtin__.module with
Python 2.7

On 02/09/2024 15:00, marc nicole via Python-list wrote:
> Hello,
> 
> I am using Python 2.7 on Windows 10 

Others have pointed out that 2.7 is unsupported and has
been for many years now. Its also inferior in most
respects including its error reporting.
If possible you should upgrade to 3.X

> from multiprocessing import Process
> def do_something(text):
> print(text)
> if __name__ == "__main__":
> q = Process(target=do_something,args=("somecmd") )
> q.start()
> # following code should execute right after the q.start() call 

So what does happen? If you put a print statement here does it execute
before or after the error message? It might make things easier to
debug(clearer error traceback) if you put the code to create the thread
into a separate function?

def do_Something(text)...

def start(fn):
   q = Process
   q.start()

if __name_
   start(do_something)
   print('Something here')


> But getting the error at the call of Process().start():
> pickle.PicklingError: Can't pickle : it's not found as
> __builtin__.module

But please show us the full error trace even if its not much.

Also check your module naming, is there a possibility
you've named your file do_something.py or similar?
(I'm guessing the function is what is being pickled?)

> anybody could provide an alternative to call the function do_something()
in
> a separate thread ?

Why not just use the Threading module?
If it's as simple as just running something in a
thread multiprocessing is probably not needed.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos



___
Tutor maillist  -  tu...@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

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