Message399603
"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. |
|
Date |
User |
Action |
Args |
2021-08-15 02:08:45 | steven.daprano | set | recipients:
+ steven.daprano, George3d6 |
2021-08-15 02:08:45 | steven.daprano | set | messageid: <1628993325.51.0.67720846108.issue44916@roundup.psfhosted.org> |
2021-08-15 02:08:45 | steven.daprano | link | issue44916 messages |
2021-08-15 02:08:44 | steven.daprano | create | |
|