-
Content Count
755 -
Joined
-
Last visited
-
Days Won
40
pyscripter last won the day on January 4
pyscripter had the most liked content!
Community Reputation
569 ExcellentTechnical Information
-
Delphi-Version
Delphi 10.3 Rio
Recent Profile Visitors
The recent visitors block is disabled and is not being shown to other users.
-
You need to decrease the refcount of these pyobjects after using them.
-
Hint: The answer is in PythonThreads · pyscripter/python4delphi Wiki (github.com) Other solutions include: Modify your scripts so that they do not create global variables (wrap everything inside a function which you execute) At the end of your python script delete (del) any global variables you create Use Run_CommandAsObjectWithDict or ExecStrings, passing new empty dictionaries to the optional locals, and globals parameters, which you then destroy.
-
Assuming you are on Windows use: import asyncio asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) loop = asyncio.new_event_loop() This should work both in the main thread and in other threads. Google for "set_wakeup_fd" to see this is a well known issue.
-
See PythonThreads · pyscripter/python4delphi Wiki (github.com) which explains how to run python code in delphi threads. This keeps the delphi main thread from blocking.
-
@iqrfYou are absolutely right, PyErr_Fetch returns new references and clears the error. The code in ProcessSystemExit has now been fixed. Thanks!
-
Wrap TDictionary - TypeError: 'Object' object is not subscriptable
pyscripter replied to iqrf's topic in Python4Delphi
TColumn.SetVisible is called, so inside that method Self is the TColumn object on which the method is called. -
The exit() function raises a SystemExit exception and if it is not handled it shuts down python. Don't use it in P4D scripts.
-
tpythondelphivar Creation of TPythonDelphiVar on-the-fly don't works as expected.
pyscripter replied to Juan C.Cilleruelo's topic in Python4Delphi
If you create an Engine client (e.g. TPythonDelphiVar TPythonModule) after the engine is initialized, you should call the client Initialize method. If the client is created before the engine is initialized, you should not call Initialize. -
Freeing TPythonModule after using it takes long
pyscripter replied to softtouch's topic in Python4Delphi
Could you post your minimal Delphi project in a zip file? -
Freeing TPythonModule after using it takes long
pyscripter replied to softtouch's topic in Python4Delphi
Destroying the engine and associated modules is normally instantaneous. Most of the demos do that. So that delay should be related to something "special" you are doing. Is python code running while you are doing that? As an aside, why do you need to manually free the engine? -
Freeing TPythonModule after using it takes long
pyscripter replied to softtouch's topic in Python4Delphi
You are not supposed to destroy TPythonModules before engine destruction. They are automatically destroyed when the engine is destroyed. And it does not achieve the desired effect of removing it from python. Python does not have a good mechanism for removing imported modules and this is not recommended in general. See for instance How do I really delete an imported module? (archive.org). Also from Reloading modules in Python - GeeksforGeeks Not sure what causes the delay. -
Wrap TDictionary - TypeError: 'Object' object is not subscriptable
pyscripter replied to iqrf's topic in Python4Delphi
Use for key in spam.myPoint.ColumnA.Keys.ToArray(): print(key) It is possible to allow for a more natural iteration, but it would require to hand craft the TDictionary wrapper. See for instance how it is done in TPyDelphiStrings in WrapDelphiClasses. -
Wrap TDictionary - TypeError: 'Object' object is not subscriptable
pyscripter replied to iqrf's topic in Python4Delphi
You could allow for both Point() and Point(x, y) by modifying CreateWith if PyArg_ParseTupleAndKeywords(args, kwds, '|ICreatePoint') then // no arguements else if PyArg_ParseTupleAndKeywords(args, kwds, 'ii|:CreatePoint', @fx, @fy) then // two integer arguements begin ... end; -
Wrap TDictionary - TypeError: 'Object' object is not subscriptable
pyscripter replied to iqrf's topic in Python4Delphi
To be able to create columns you need to also to customize the TColumn wrapper: TColumnWrapper = class(TPyClassWrapper<TColumn>) constructor CreateWith(APythonType: TPythonType; args, kwds: PPyObject); override; end; constructor TColumnWrapper.CreateWith(APythonType: TPythonType; args, kwds: PPyObject); var W: integer; P: PPyObject; begin Create(APythonType); GetPythonEngine.PyArg_ParseTuple(args, 'iO:CreateColumn', @W, @P); DelphiObject := TColumn.Create; DelphiObject.Width := W; DelphiObject.Visible := GetPythonEngine.PyObject_IsTrue(P) = 1; end; then register it in Form.Create PyDelphiWrapper.RegisterDelphiWrapper(TColumnWrapper).Initialize; PyDelphiWrapper.RegisterDelphiWrapper(TPyClassWrapper<TDictionary<string, TColumn>>).Initialize; Then the following code works: from spam import myPoint, Column print(myPoint.ColumnA['Note'].Width) print(myPoint.ColumnA['Note'].Visible) new_column = Column(100, False) myPoint.ColumnA.Add('Note1', new_column) print(myPoint.ColumnA['Note1'].Width) print(myPoint.ColumnA['Note1'].Visible) -
Wrap TDictionary - TypeError: 'Object' object is not subscriptable
pyscripter replied to iqrf's topic in Python4Delphi
Assuming your register the dictionary as shown above the following works. from spam import myPoint print(myPoint.ColumnA['Note'].Width) print(myPoint.ColumnA['Note'].Visible)