Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

Don't get stuck in a closet -- wear yourself out.


comp / comp.lang.python / Re: Process.start

SubjectAuthor
* Re: [Tutor] Getting a Process.start() error pickle.PicklingError:marc nicole
`* Re: Process.startStefan Ram
 `- Re: Process.startKeith Thompson

1
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
From: marc nicole
Newsgroups: comp.lang.python
Date: Tue, 3 Sep 2024 09:34 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: mk1853387@gmail.com (marc nicole)
Newsgroups: comp.lang.python
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
Date: Tue, 3 Sep 2024 11:34:53 +0200
Lines: 109
Message-ID: <mailman.29.1725356105.2917.python-list@python.org>
References: <CAGJtH9Tw0ZoB51XCA_4=CGu8cO6LoKw9RF5pBuYDoQJfHA6h_g@mail.gmail.com>
<vb6i3c$2dt$1@ciao.gmane.io>
<CAGJtH9Skc3ei1VzNock=w_-CoLtyMm-+TbRgMxsFDH1Mr7FROQ@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de 0luPinS6qUElkp2vmkvXWwjdJZDUx0MzzyUlhXcrqFQg==
Cancel-Lock: sha1:708E5VepukBqRA6XwGORiRR0hRQ= sha256:kedoc/d2oBmBZ24801R5ltG6YNmbSFtLpzIt5G1Y0dk=
Return-Path: <mk1853387@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=g8s5uwN0;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.000
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'def': 0.04; 'thread':
0.05; 'world"': 0.05; '"hello': 0.07; 'subject:error': 0.07;
'subject:module': 0.07; '-\xc2\xa0': 0.09; '2.7': 0.09; 'cc:addr
:python-list': 0.09; 'skip:\xc2 20': 0.09; 'subject:not': 0.09;
'subject:skip:P 10': 0.09; 'subject:Python': 0.12; '&gt;': 0.14;
'import': 0.15; 'url:mailman': 0.15; 'that.': 0.15; "(i'm": 0.16;
'2024': 0.16; '3.x': 0.16; 'alan,': 0.16; 'displayed': 0.16;
'flickr': 0.16; 'gauld': 0.16; 'message?': 0.16; 'photo-blog':
0.16; 'pickle': 0.16; 'question,': 0.16; 'subject: <': 0.16;
'subject:() ': 0.16; 'subject:2.7': 0.16; 'subject:found': 0.16;
'subject:skip:p 20': 0.16; 'threading': 0.16; 'url-
ip:79.170.44.132/32': 0.16; 'url-ip:79.170.44/24': 0.16; 'url-
ip:79.170/16': 0.16; 'url-ip:79/8': 0.16; 'url:alan-g': 0.16;
'url:alan_gauld': 0.16; 'url:alangauldphotos': 0.16; 'url:tutor':
0.16; 'wrote:': 0.16; 'problem': 0.16; 'python': 0.16; 'probably':
0.17; "can't": 0.17; 'url:amazon': 0.19; 'cc:addr:python.org':
0.20; 'subject:: [': 0.21; 'subject:] ': 0.21; 'skip:_ 10': 0.22;
'code': 0.23; 'cc:2**1': 0.23; 'url-ip:188.166.95.178/32': 0.25;
'url-ip:188.166.95/24': 0.25; 'url:listinfo': 0.25; 'url-
ip:188.166/16': 0.25; 'normally': 0.26; 'function': 0.27; 'email
addr:python.org&gt;': 0.28; 'error': 0.29; 'skip:_ 40': 0.31;
'module': 0.31; 'url-ip:188/8': 0.31; 'program': 0.31; 'think':
0.32; 'anybody': 0.32; 'python-list': 0.32; 'returning': 0.32;
'subject:Can': 0.32; 'subject:Tutor': 0.32; 'message-
id:@mail.gmail.com': 0.32; 'but': 0.32; 'there': 0.33; 'windows':
0.34; 'header:In-Reply-To:1': 0.34; 'received:google.com': 0.34;
'running': 0.34; 'following': 0.35; 'from:addr:gmail.com': 0.35;
'display': 0.36; 'change': 0.36; "skip:' 10": 0.37; 'using': 0.37;
"it's": 0.37; 'author': 0.37; 'others': 0.37; 'file': 0.38;
'could': 0.38; 'put': 0.38; 'thanks': 0.38; 'use': 0.39; 'much.':
0.39; 'neither': 0.39; 'alan': 0.40; 'learn': 0.40; 'something':
0.40; 'hello,': 0.40; 'should': 0.40; 'including': 0.60;
'provide': 0.60; 'tutor': 0.61; 'skip:\xc2 10': 0.62; 'here':
0.62; 'follow': 0.62; '8bit%:9': 0.64; 'full': 0.64; 'upgrade':
0.64; 'your': 0.64; 'named': 0.65; 'years': 0.65; 'skip:t 20':
0.66; 'url-ip:18/8': 0.67; 'right': 0.68; 'url:author': 0.69;
'site': 0.70; 'unsubscribe': 0.72; 'mar.': 0.84; 'respects': 0.84;
'skip:p 50': 0.84; 'subject: \n ': 0.84; 'world&quot;': 0.84;
'\xc3\xa9crit\xc2\xa0:': 0.84; 'subject:type': 0.91
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20230601; t=1725356102; x=1725960902; darn=python.org;
h=cc:to:subject:message-id:date:from:in-reply-to:references
:mime-version:from:to:cc:subject:date:message-id:reply-to;
bh=4ol645Yz9JOPde5gmRgW00QDbm7O9mQUy6td4QAoItY=;
b=g8s5uwN0jNRDlukJAn8KLgTD4SocdP9nBGw+60FgO+qcf346q1UmTzhKoYPwyj+qRO
vjQNYGGxndb0Yi+OELZU5mAlrEXR7t4MsEhSkSFZ5WNw+hqoFR+Pur10udNCsNomN5yD
XAck+KGQHTP+xPeNEkF2dXql2nzIIW0zjLtmYcbU7G/8Lh6/nUSHosADiAfbaDpqbv9j
HM1yVcrcWgNVBT6VFrnDu6LIYLMojvmSkakqJCBY2044EVBSqvbU7TVTXb7S9iF+8keb
8TbFFeEKsBPc58sSleppqcq3REuJtNjtq8PT6G6Z756BQUvZ5hrTuFj7T8gbpmjgcXhQ
Y8yQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20230601; t=1725356102; x=1725960902;
h=cc:to:subject:message-id:date:from:in-reply-to:references
:mime-version:x-gm-message-state:from:to:cc:subject:date:message-id
:reply-to;
bh=4ol645Yz9JOPde5gmRgW00QDbm7O9mQUy6td4QAoItY=;
b=C7AtoRJmpBAjfI+2DQlOjEAK58grLXlTYTDMXxWuSjlbasEzOOO562BeHAJ1p9q8Ra
ElxYUnd3zWh8Ps2BWoVHU+tClhF7L16GtKEa0/xH98nuPVx0igZzTACkZZdq3w3h+HZ2
LGAWSGroz+e3dqRuAjzIDo3hnYyIHBKmrxXa/5DJ8ZUieGFrb3shYsM0EM0gbLfifEao
qNWdTUbO8N22/Fk4iEJCn1UYbAQAKb++0Eymc5LvUOWS5NimnQSKF5nks/ksbcHbWreE
AZSl+sK4c/2f9eflVWV/+G6ru6Q6NI6Ue7c9KFIP6nV9VJCr5MmtXXHlmOeuZGsd+Uo0
/4Qg==
X-Forwarded-Encrypted: i=1;
AJvYcCUATVimTFtOjOyb+XynYfAlq3HY7/ADG0COJs8M1xxmgrhKmTqkUcH6NzPwx5U6PiNc/Iszg1C0AwWQlg==@python.org
X-Gm-Message-State: AOJu0YzqgQd64m4MZPlTVk2XEYLw0TZpTNm/rbi9SPoQQqL/sWzLysG8
KDj9HaseIxmI4vWRmmPqhyju7VVnNmUq3RLAdUcNdYxURL8AFPsD/nIn2KfLDLZKTR3VBnDPqHN
iSK0mV1Uy2JAEP+vKhmCxLAWzwn+SDK3c
X-Google-Smtp-Source: AGHT+IGkEmRk/z7kT2+L08ALCYsRjQYlGcKMzv3HcNB+rfQaCzqGNt702zFGzSh/EisjZMmgXRqJNfMYPQPWy3lSAY4=
X-Received: by 2002:a05:690c:1d:b0:6c1:2ea1:c24d with SMTP id
00721157ae682-6d40e38a1b1mr162328407b3.26.1725356102515; Tue, 03 Sep 2024
02:35:02 -0700 (PDT)
In-Reply-To: <vb6i3c$2dt$1@ciao.gmane.io>
X-Content-Filtered-By: Mailman/MimeDel 2.1.39
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <CAGJtH9Skc3ei1VzNock=w_-CoLtyMm-+TbRgMxsFDH1Mr7FROQ@mail.gmail.com>
X-Mailman-Original-References: <CAGJtH9Tw0ZoB51XCA_4=CGu8cO6LoKw9RF5pBuYDoQJfHA6h_g@mail.gmail.com>
<vb6i3c$2dt$1@ciao.gmane.io>
View all headers

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
>

Subject: Re: Process.start
From: Stefan Ram
Newsgroups: comp.lang.python
Organization: Stefan Ram
Date: Tue, 3 Sep 2024 13:02 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: Process.start
Date: 3 Sep 2024 13:02:30 GMT
Organization: Stefan Ram
Lines: 43
Expires: 1 Jul 2025 11:59:58 GMT
Message-ID: <threads-20240903140046@ram.dialup.fu-berlin.de>
References: <mailman.29.1725356105.2917.python-list@python.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de TgmIFcF53xIdeeKyoRY3VAoErTXrGVU7Gq2KUzMQPN6FRR
Cancel-Lock: sha1:oHuXnj+TKtCwgldHzZsEtNg7Jzk= sha256:ZosjGFSf5Ia3/Cao+aGuXlQ+FoD+88/TdjlMC5F1acg=
X-Copyright: (C) Copyright 2024 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
View all headers

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.

Subject: Re: Process.start
From: Keith Thompson
Newsgroups: comp.lang.python
Organization: None to speak of
Date: Tue, 3 Sep 2024 20:47 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S.Thompson+u@gmail.com (Keith Thompson)
Newsgroups: comp.lang.python
Subject: Re: Process.start
Date: Tue, 03 Sep 2024 13:47:13 -0700
Organization: None to speak of
Lines: 39
Message-ID: <87wmjs1n3i.fsf@nosuchdomain.example.com>
References: <mailman.29.1725356105.2917.python-list@python.org>
<threads-20240903140046@ram.dialup.fu-berlin.de>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Tue, 03 Sep 2024 22:47:14 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="50c6ce2cfb1ba441daef0e852a430a3c";
logging-data="3645393"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18dQycRqV9DP23X8uUIcMaK"
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:MC0058TtkpGSJ/O6dLhADd33vT4=
sha1:ShBKHou85aKcEikYrvzLaARbpj0=
View all headers

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

1

rocksolid light 0.9.8
clearnet tor