Nefari0 0 Posted December 10, 2022 (edited) Hi! Have a some issue - lxml in TPythonThread with Delphi don´t works but it works in OwnThreadstate with the same script Code: from lxml import html it calls the error - this module can only be loaded into one interpreter per process And when I try to run Code: BeautifulSoup(html_source,"lxml") it calls the error - FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library? but in OwnThreadstate with the same script works good. Same way the Code: BeautifulSoup(html_source,"html.parser") in TPythonThread is works, but I need lxml glad to any suggestions Edited December 10, 2022 by Nefari0 adding info Share this post Link to post
SwiftExpat 65 Posted December 10, 2022 (edited) Likely just call CoInitialize CoInitialize(nil); try ... your code here finally CoUninitialize(); end; Edited December 11, 2022 by SwiftExpat Updates based on feeback Share this post Link to post
Nefari0 0 Posted December 10, 2022 (edited) I'll try to understand it. Thanks Edited December 10, 2022 by Nefari0 Share this post Link to post
David Heffernan 2345 Posted December 10, 2022 3 hours ago, SwiftExpat said: Likely just call CoInitialize try CoInitialize(nil); ... your code here finally CoUninitialize(); end; This code is wrong. The try is always placed after the resource has been acquired. Share this post Link to post
SwiftExpat 65 Posted December 11, 2022 (edited) 19 hours ago, David Heffernan said: This code is wrong I think I get you point, would you write it like this? edited above based on feeback Edited December 11, 2022 by SwiftExpat remove misleading code Share this post Link to post
David Heffernan 2345 Posted December 11, 2022 No. CoInitialize doesn't report errors by throwing exceptions. You are expected to check its return value. This is stated clearly in the documentation for the function which is required reading before using it. Let's leave error handling to one side for now though. The try finally pattern is like this. res := acquireResource; try res.doSomething; finally releaseResource(res); end; The try/finally is protecting the code *between* acquisition and release. Therefore the try must be *after* acquisition. 1 Share this post Link to post