This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author steven.daprano
Recipients George3d6, steven.daprano
Date 2021-08-15.02:08:44
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1628993325.51.0.67720846108.issue44916@roundup.psfhosted.org>
In-reply-to
Content
"Undefined behaviour" has a particular meaning to C programmers, which is relevant to Python because the interpreter is written in C. It's probably best not to use that term here.

Let me see if I understand your issue.

* You have two separate Python processes.

* Each process has a thread which dynamically writes a file called "m1.py", containing a class C.

* Each process has a second thread which dynamically writes a file called "m2.py", also containing a class C.

* Each thread then imports its file using the common name "M", and tries to pickle and unpickle objects of type C.

* And seemingly at random, each thread sometimes picks up its class M.C, but sometimes the class M.C from the other thread.

* Not sure if you get any cross-process contamination as well (that is, process 1 picks up the modules from process 2), but it wouldn't surprise me in the least.


My instinct here is to back away in horror *wink*

You have a lot of non-deterministic code here. I'm kinda impressed that it ever works at all :-)

1. If you have two processes writing to the same file "m1.py", its a lottery which one will end up actually written to disk. It is at least theoretically possible that the data actually on the disk could be a hybrid of bits of process 1's m1.py and bits of process 2's m1.py.

2. Likewise for the file m2.py.

3. When you go to import the files, it is non-deterministic which file you will see, e.g.

- process 1 writes its m1.py
- process 2 writes its m1.py, overriding the previous m1.py
- process 1 goes to import m1.py, but ends up reading the m1.py
  created by process 2

So that's how you could get cross-process contamination.
History
Date User Action Args
2021-08-15 02:08:45steven.dapranosetrecipients: + steven.daprano, George3d6
2021-08-15 02:08:45steven.dapranosetmessageid: <1628993325.51.0.67720846108.issue44916@roundup.psfhosted.org>
2021-08-15 02:08:45steven.dapranolinkissue44916 messages
2021-08-15 02:08:44steven.dapranocreate