Jump to content

CBAPKA

Members
  • Content Count

    7
  • Joined

  • Last visited

Community Reputation

0 Neutral

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. CBAPKA

    How I can clear engine after exec script ?

    Thank you, I've managed to solve some of my issues, but the best solution - to remove these variables from Python. procedure Thread.ExecuteWithPython; begin inherited; with GetPythonEngine do Run_CommandAsObjectWithDict(code, file_input, PyDict_New, PyDict_New); end;
  2. procedure Thread.ExecuteWithPython; begin inherited; var Lines: TStringlist := TStringlist.Create; Lines.Text := code; var ppO: PPyObject; try ppO := GetPythonEngine.Run_CommandAsObject(Lines.Text, file_input, '<string>'); finally FreeAndNil(Lines); GetPythonEngine.Py_DECREF(ppO); end; end; Okay, I has new problem, I tried understand this, but cant. Oken I can exec script as example a = 10 Script was executed procedure TMainForm.TerminateThread(Sender: Tobject); var th: Thread absolute Sender; begin work := false; TPythonThread.Py_End_Allow_Threads; ShowMessage('ready!'); end; and I launch againt but code python now is: print(a) And he knew about this variable, it shouldn't be like this... I have a Telegram database that is blocked after initializing the TelegramClient variable. I need to free up memory after executing the code, because I have many different pieces of Python code that are executed by pressing different buttons, but the engine is the same, so it needs to be cleaned up somehow. I tried to Google the information, but it's difficult when you don't understand much, and even more difficult when there is very little information)
  3. CBAPKA

    Async script with PythonThread

    Thank you very much. You have solved my problem.
  4. CBAPKA

    Async script with PythonThread

    I read it, but my problem in this: GetPythonEngine.ExecStrings(Lines); Lines: import asyncio loop = asyncio.new_event_loop () and got error: ValueError: set_wakeup_fd only works in main thread of the main interpreter my task is just to run asynchronous code in python, without hanging the delphi interface itself, but it turns out that pythonThread From delphi Wraps the script into a thread and I do not know how to get the Loop of the Main thread
  5. Is there any way I can run the script without the main thread hanging? I can run the code in a stream, but I don't understand how it works to the end, because I can execute the code in PyCharm and everything works fine. For example, I initialize the stream directly inside the python script, put the code into it, but the Library telethon that performs the task throws the error "There is no current event loop" или "There is no current event loop in thread 'Thread-1 (main)'." или "There is no current event loop in thread 'Dummy-1'." In pycharm that work as def CreateConnect(path: str, proxy, api_hash, api_id, device=None, system=None, loop=None): TC = TelegramClient( api_hash=api_hash, api_id=api_id, session=path, timeout=60, device_model=device, system_version=system, proxy=proxy, loop=loop ) try: TC.connect() if TC.is_connected(): return TC else: return False except Exception as e: print(f'error {path}: {e}') return False def main(loop): asyncio.set_event_loop(loop) #... tg = CreateConnect(path=f'{accPath}\\{account}\\telethon.session', proxy=proxy, api_hash=settings['telethon']['api_hash'], api_id=settings['telethon']['api_id'], device=settings['telethon']['device_model'], system=settings['telethon']['system_version'], loop=loop ) if __name__ == '__main__': loop = asyncio.new_event_loop() p = threading.Thread(target=main, args=(loop,)) p.start() but in delphi, the Thread is initialized on top of the module, as I understood it
  6. CBAPKA

    python4delphi How to stop inifinity script

    import time while True: print('something') timer.sleep(5) #need to stop it
  7. Greetings, I have several pieces of Python code that checks one condition in a loop, if it is met, it outputs Print, if not waits 5 seconds and checks again, and so on endlessly. How do I stop the script using delphi? Can I somehow send ctrl+c or something like that there. The answer from Demo33 did not fit v - 3.12.dll
×