• Re: [Tutor] Getting a Process.start() error pickle.PicklingError: Can'

    From marc nicole@3:633/280.2 to All on Tue Sep 3 19:34:53 2024
    Subject: Re: [Tutor] Getting a Process.start() error pickle.PicklingError:
    Can't pickle <type 'module'>: it's not found as __builtin__.module with
    Python 2.7

    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 =3D Process(target=3Dfn, args=3D())
    p.start()

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

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

    if __name__ =3D=3D "__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 =C3=A0 10:48, Alan Gauld via Tutor <tutor@python.org> =
    a
    =C3=A9crit :

    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__ =3D=3D "__main__":
    q =3D Process(target=3Ddo_something,args=3D("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 =3D 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 <type 'module'>: 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 - Tutor@python.org
    To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor


    --- MBSE BBS v1.0.8.4 (Linux-x86_64)
    * Origin: ---:- FTN<->UseNet Gate -:--- (3:633/280.2@fidonet)
  • From Stefan Ram@3:633/280.2 to All on Tue Sep 3 23:02:30 2024
    marc nicole <mk1853387@gmail.com> 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!

    Now the question, when to use Process/Multiprocess and when to use
    Threading in Python?

    When it comes to processes vs. threads, it's like choosing
    between a burrito and a taco.

    Use processes for those CPU-heavy tasks to get that real
    parallel action across multiple cores, dodging Python's GIL
    like it's rush hour on the 405.

    Processes are also tougher than a two-dollar steak and perfect
    for memory hogs.

    On the flip side, threading's your go-to for I/O-bound tasks
    where the GIL takes a breather during I/O ops, letting you
    multitask like a boss. Threads are as light as a surfer's
    board, play nice with shared memory, and are the bee's knees
    for juggling a ton of tasks without breaking a sweat.



    --- MBSE BBS v1.0.8.4 (Linux-x86_64)
    * Origin: Stefan Ram (3:633/280.2@fidonet)
  • From Keith Thompson@3:633/280.2 to All on Wed Sep 4 06:47:13 2024
    ram@zedat.fu-berlin.de (Stefan Ram) writes:
    marc nicole <mk1853387@gmail.com> 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.Thompson+u@gmail.com
    void Void(void) { Void(); } /* The recursive call of the void */

    --- MBSE BBS v1.0.8.4 (Linux-x86_64)
    * Origin: None to speak of (3:633/280.2@fidonet)
  • From avi.e.gross@gmail.com@3:633/280.2 to All on Wed Sep 4 15:19:12 2024
    Subject: RE: [Tutor] Getting a Process.start() error pickle.PicklingError:
    Can't pickle <type 'module'>: it's not found as __builtin__.module with
    Python 2.7

    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 <tutor-bounces+avi.e.gross=gmail.com@python.org> On Behalf Of
    Alan Gauld via Tutor
    Sent: Tuesday, September 3, 2024 4:41 AM
    To: tutor@python.org
    Cc: python-list@python.org
    Subject: Re: [Tutor] Getting a Process.start() error pickle.PicklingError: Can't pickle <type 'module'>: 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 <type 'module'>: 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 - Tutor@python.org
    To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor


    --- MBSE BBS v1.0.8.4 (Linux-x86_64)
    * Origin: ---:- FTN<->UseNet Gate -:--- (3:633/280.2@fidonet)