Skip to content
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

I used your component for UniGUI and it worked fine for a while, but... #492

Closed
mdavodnia opened this issue Dec 27, 2024 · 12 comments
Closed

Comments

@mdavodnia
Copy link

I used your component for UniGUI and it worked fine for a while, probably, but after I installed Delphi 12, the program stopped working and gave an error
I created a component like the VCL component for UniGUI
It worked fine and displayed the result of executing Python commands in the Uni editor, but I don't know what happened and now it doesn't work properly
Do you have any ideas?

@pyscripter
Copy link
Owner

pyscripter commented Dec 27, 2024

and gave an error

The info you provide is insufficient to provide any help.

  • What is the error you get?
  • Where exactly does the error occur?
  • Does your app still work when you compile with Delphi 11?

@mdavodnia
Copy link
Author

hi,Thank you for your attention.
create testcase and send For U

@mdavodnia
Copy link
Author

1- I am Create Component For Use In Unigui(MDpyUni)
2-create test Case For Use In Unigui Prog(MDPythonEditor)
3-Run In Browser
4-load dll -OK
5-Excute Python String Command And ocurrected Error
1-setupPyUni_Component
2-SetDirUniSetup
4-On Run Uni Sample Error
Screenshot 2024-12-28 125705

testcase link download:

https://filebin.net/2fh9o1r3h76olt91

@mdavodnia
Copy link
Author

testcase link download:

https://filebin.net/2fh9o1r3h76olt91

@pyscripter
Copy link
Owner

pyscripter commented Dec 28, 2024

You appear to have done substantial work wrapping the UniGUI components. However, the test case is not of much use to me since I do not have UniGUI. A standard and simple test project capturing the essence of what you are doing and reproducing the error would be useful instead. Also, you have not answered my questions:

  • What is the error you get?
  • Where exactly does the error occur? Is it in line 5100? If that is the case the error has occurred before executing the script.
  • Does your app still work when you compile with Delphi 11?

Also which python version and distribution are you using? Finally your version of PythonEngine.pas is not the same as the latest version in this repo. Please upgrade to the latest version of this repo and try again.

@mdavodnia
Copy link
Author

error Get
--> Access violation at address 7AB23F95 in module 'python313.dll' (offset 243F95). Read of address 00000048.

yes Error on line 5099 and 5011 efect But the line does not appear the first time, the second time the command .ExecStrings('pythoncode') is executed, it gives an error.

Does your app still work when you compile with Delphi 11?
yes,on delphi 11 same 12 has error

@mdavodnia
Copy link
Author

It seems that after running a Python command once, the dll gets locked and cannot be run again.

@mdavodnia
Copy link
Author

I Love U,
has be OK,Tanks,Tanks
5

@pyscripter
Copy link
Owner

has be OK,Tanks,Tanks

Could you please explain what you found?

@mdavodnia
Copy link
Author

yes I comment From Line 9384 to 9396

// Forbid printing for any other thread than the main one
(* {$IFNDEF FPC}
if GetCurrentThreadId <> MainThreadId then
with GeTPythonEngine do
begin
if RedirectIO and (IO <> nil) and (IO.ClassName <> 'TPythonInputOutput') and not IO.DelayWrites then
begin
Result := GeTPythonEngine.ReturnNone;
Exit;
end;
end;
{$ENDIF}
*)

@pyscripter
Copy link
Owner

pyscripter commented Dec 28, 2024

How using Delphi 11 makes a difference?

The code you deleted is fine. If you are printing from threads you should either:

  1. Use a TPythonInputOuput descendent like TPythonGUIInputOutput with DelayWrites set to True
  2. or Use a TPythonInputOutput and handle the OnSendUniData in a thread safe manner.

@pyscripter
Copy link
Owner

pyscripter commented Dec 28, 2024

Also if you are running Python from multiple threads or even from a thread other than the MainThread, you should read https://github.com/pyscripter/python4delphi/wiki/PythonThreads very carefully. Otherwise you will get seemingly random access violations. The crashes you experienced may well be related to that and not on Delphi 12.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants