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

Liste des GroupesRevenir à cl python 
Sujet : 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
De : mk1853387 (at) *nospam* gmail.com (marc nicole)
Groupes : comp.lang.python
Date : 03. Sep 2024, 10:34:53
Autres entêtes
Message-ID : <mailman.29.1725356105.2917.python-list@python.org>
References : 1 2 3
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 <tutor@python.org> 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 <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
>

Date Sujet#  Auteur
3 Sep 24 * Re: [Tutor] Getting a Process.start() error pickle.PicklingError: Can't pickle <type 'module'>: it's not found as __builtin__.module with Python 2.73marc nicole
3 Sep 24 `* Re: Process.start2Stefan Ram
3 Sep 24  `- Re: Process.start1Keith Thompson

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal