why I cannot to install packages?
[image: image.png] -- https://mail.python.org/mailman/listinfo/python-list
Re: why I cannot to install packages?
> On 15 Sep 2022, at 12:31, נתי שטרן <[email protected]> wrote: > > [image: image.png] Images are stripped; please copy the text of the error you are seeing and post that. Barry > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.9.14
> On 14 Sep 2022, at 14:03, אורי <[email protected]> wrote: > > Hi, > > Python 3.9.14 has been released on Sept. 6, 2022. As I can see written on > https://www.python.org/downloads/release/python-3914/: > > According to the release calendar specified in PEP 596, Python 3.9 is now > in the "security fixes only" stage of its life cycle: the 3.9 branch only > accepts security fixes and releases of those are made irregularly in > source-only form until October 2025. Python 3.9 isn't receiving regular bug > fixes anymore, and binary installers are no longer provided for it. Python > 3.9.13 was the last full bugfix release of Python 3.9 with binary > installers. > > > Is there a safe way to install a 64-bit version of Python 3.9.14 on Windows? What is stopping you using 3.10? If 3.9 is important then I guess you will need to build it for yourself. Barry > > Thanks, > Uri. > אורי > [email protected] > -- > https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Can you mock a C function using ctypes?
I've done unit testing of C functions using ctypes, and that works nicely until you need to provide a stub/mock function to be called by the C code under test. Can that be done using ctypes? For example, I open a library that contains functon foo() where foo() calls external function bar() which is not contained in the library. Then, I provide a Python bar() function that gets called by foo() when foo() is called? I suspect the anser is "no". I did a bit of googling, and found this question asked on Stack Overflow a few years ago, but the answer made no sense. It appeared to be ansering a different question, but I couldn't quite figure out what that question was. -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: Can you mock a C function using ctypes?
On 9/15/22, Grant Edwards wrote: > > Can that be done using ctypes? > > For example, I open a library that contains functon foo() where foo() > calls external function bar() which is not contained in the library. > Then, I provide a Python bar() function that gets called by foo() when > foo() is called? That's straight forward if the library allows the application to pass a function pointer to bar(). ctypes function prototypes are defined by ctypes.CFUNCTYPE(restype, *argtypes, use_errno=False, use_last_error=False) for the cdecl calling convention, or similarly by ctypes.WINFUNCTYPE() to use the Windows stdcall calling convention. A prototype can be instantiated as a function pointer that calls a Python function, e.g. c_bar = prototype(bar). -- https://mail.python.org/mailman/listinfo/python-list
Book/resource recommendation about Celery?
Hi, I'm using Flask + Celery + RabbitMQ. Can anyone recommend a good book or other resource about Celery? Thanks! Albert-Jan -- https://mail.python.org/mailman/listinfo/python-list
Re: Can you mock a C function using ctypes?
On 2022-09-15, Eryk Sun wrote: > On 9/15/22, Grant Edwards wrote: >> >> Can that be done using ctypes? >> >> For example, I open a library that contains functon foo() where foo() >> calls external function bar() which is not contained in the library. >> Then, I provide a Python bar() function that gets called by foo() when >> foo() is called? > > That's straight forward if the library allows the application to pass > a function pointer to bar(). That's typically not the case. Does the pointer have to be passed? Or can it be "poked" into a global variable? If so, I guess it would be fairly trivial to write a dummy version of bar() in C that calls a function via a global pointer that could be set via ctypes? > ctypes function prototypes are defined by ctypes.CFUNCTYPE(restype, > *argtypes, use_errno=False, use_last_error=False) for the cdecl > calling convention, or similarly by ctypes.WINFUNCTYPE() to use the > Windows stdcall calling convention. A prototype can be instantiated > as a function pointer that calls a Python function, e.g. c_bar = > prototype(bar). -- https://mail.python.org/mailman/listinfo/python-list
Re: Can you mock a C function using ctypes?
On 9/15/22, Grant Edwards wrote:
>
> Does the pointer have to be passed? Or can it be "poked" into a global
> variable?
If the library exports the function pointer as a global variable, it
can be set in ctypes using the in_dll() method. Unfortunately, as far
as I know, a ctypes function prototype can't be used directly for
this, at least not easily, since the function pointer it creates
doesn't have a `value` or `contents` attribute to set the target
address. Instead, the exported global can be accessed as a void
pointer. It's clunky, but it works.
For example, Python's REPL supports a callback for reading a line from
the terminal. Normally it's either hooked by a C extension, such as
the readline module, or set to the default function
PyOS_StdioReadline(). We can use a ctypes callback to hook into this
and chain to the previous function.
import ctypes
PyOS_RFP = ctypes.CFUNCTYPE(
ctypes.c_void_p,
ctypes.c_void_p, # stdin (FILE *)
ctypes.c_void_p, # stdout (FILE *)
ctypes.c_char_p, # prompt
)
@PyOS_RFP
def readline_hook(stdin, stdout, prompt):
print('HOOKED: ', end='', flush=True)
return prev_rfp(stdin, stdout, prompt)
rfp_vp = ctypes.c_void_p.in_dll(ctypes.pythonapi,
'PyOS_ReadlineFunctionPointer')
if rfp_vp:
# there's a previous RFP that can be hooked
prev_rfp = ctypes.cast(rfp_vp, PyOS_RFP)
rfp_vp.value = ctypes.cast(readline_hook, ctypes.c_void_p).value
In this trivial example, "HOOKED: " is printed to the terminal before
each line is read:
HOOKED: >>> def f():
HOOKED: ... pass
HOOKED: ...
HOOKED: >>>
Note that I defined the return type of PyOS_RFP to be c_void_p. Using
c_char_p as the return type would convert the result to a bytes
object, which is wrong in this case. If the setfunc of the callback's
return type has to keep a reference to a converted Python object, such
as a bytes object, then the callback has no choice but to leak the
reference in order to keep the object alive indefinitely, which
usually causes a memory leak.
--
https://mail.python.org/mailman/listinfo/python-list
