-
Notifications
You must be signed in to change notification settings - Fork 417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deepcopy failed on _thread.lock #565
Comments
Have you tried googling the error? |
Yes, in fact I did google it, but I'm not sure if it's a general thing caused by the multiprocess nature of flet. When I run the Program without GUI, the code is working. When the method with utilizes the deepcopy is called from a flet GUI Button, it crashes with the error mentioned above. I guess I need to find a way to omit _thread.lock from being copied or run the whole method single threaded. But I have no clue so far, where to start this endeavor. |
Could you do a simple repro, so we could investigate? |
Here a little working example. The problem is the deepcopy of the ListElementClass object, which is a flet.Text object, I think.
By producing this example code, I thought that maybe I should keep the values outside any flet object and store them in a different datastructure to do the deepcopy on that datastructure... @FeodorFitsner And a word of Thank You for this nice project! I really appreciate your work here. |
So I came up with a solution to this issue. There is a class which is subject to the deepcopy process. This class itself has an attribute
I hope my failure will be of help to anybody else. Thanks again for the project and the fast response! |
Issue seems closed. Did you manage to get it fixed? |
Well, I exclude objects of flet classes from the deepcopy by overriding the Deepcopy of flet Elements is still not possible. I don't know where to start investigating this issue, so I just excluded flet-objects in my project. I created an even simpler Example to show the issue:
I don't know if reopening the issue would be any good, as flet objects maybe shouldn't be deepcopied at all? |
So, I just faced this same issue, and I actually confirm that flet controls can't be deepcopied. Please @FeodorFitsner investigate on this. import copy
import flet as ft
def main(page: ft.Page):
text = ft.Text("Hello")
mycopy = copy.deepcopy(text)
page.add(
ft.Text("Hello")
)
ft.app(target=main) Error:
This issue should be reopened. If it can't then I can maybe create another one. |
We could provide a custom |
I will give it a try. |
I mean when you implement |
So, I am now on this issue and understand exactly from where the error comes. |
those locks are needed for proper functioning. |
Implementation looks good to me - I'd probably start with that :) |
So, I found where the issue is from. I added a print in the except clause, so as to see the key value pairs that couldn't be deepcopied: except TypeError:
print(k, v)
# pass And had this:
The building blocks of the DataTable apparently also raise a type error, and hence result in the image i sent above. |
I also went forward modifying the for k, v in self.__dict__.items():
try:
cls.__dict__[k] = copy.deepcopy(v, memo)
except TypeError as error:
print(f"{error=}\n{k=}\n{v=}\n") And had the below error: error=TypeError("cannot pickle '_thread.lock' object")
k='_lock'
v=<unlocked _thread.lock object at 0x000001579E147C40>
error=TypeError("DataColumn.__init__() missing 1 required positional argument: 'label'")
k='_DataTable__columns'
v=[<flet.datatable.DataColumn object at 0x000001579E12F590>, <flet.datatable.DataColumn object at 0x000001579E146890>]
error=TypeError("cannot pickle '_thread.lock' object")
k='_lock'
v=<unlocked _thread.lock object at 0x000001579E147300>
error=TypeError("DataCell.__init__() missing 1 required positional argument: 'content'")
k='_DataRow__cells'
v=[<flet.datatable.DataCell object at 0x000001579E146D50>, <flet.datatable.DataCell object at 0x000001579E147090>]
error=TypeError("cannot pickle '_thread.lock' object")
k='_lock'
v=<unlocked _thread.lock object at 0x000001579E147B00>
error=TypeError("DataCell.__init__() missing 1 required positional argument: 'content'")
k='_DataRow__cells'
v=[<flet.datatable.DataCell object at 0x000001579E1475D0>, <flet.datatable.DataCell object at 0x000001579E147910>] The error could be solved by modifying this line, so the cls = self.__class__() I need some help please. |
My thinking is that you have to override |
I think I have to make a PR so you see how things move. |
I'm trying to build a little board game with a reasonably smart computer opponent. For that, I need deepcopy to find the best next move. Using copy.deepcopy gives me the following error. Any hints for getting this to work would be great!
Python 3.10 on Ubuntu is in use here...
I skipped some reoccurring lines
The text was updated successfully, but these errors were encountered: