Re: callbacks and threading

"Diez B. Roggisch" <[email protected]> Sun, 28 Aug 2016 17:29:04 +0200
Newsgroups gmane.comp.python.ctypes
Message-ID <[email protected]>
It is not possible for ctypes (or anything else, for that matter) to force a running thread to execute arbitrary other code, and the just jump back to execution.

I see two options that need investigation:

 - currentThread is for whatever reason confused. You could try that out by making your callback stall for several seconds (time.sleep), and observe if the mainloop is still running.
 - the mainloop you describe is an actual eventloop, in which case the design of your application needs to be altered. For this we would need to see more code.

So - which is it?

Diez


> On 19 Aug 2016, at 23:44, KP <[email protected]> wrote:
> 
> I have a python client with ctypes wrappers to call in to a DLL that in turn talks to a server process. One of the features is to register a callback on an event. I am able to successfully register callbacks, and they do get called on events...so all is working well there.
> 
> However, it seems the callbacks are always executed in the "main" thread...even when I know there are other commands running in the main thread.
> 
> I'm not entirely sure how this happens/or is possible.  The main thread is running a loop, but the callback also reports being in the main thread (by printing threading.currentThread()). Is this something ctypes has control over that I can tweak?
> 
> I need it to be in a different thread so that any CTRL-C will _not_ end up in that thread, and will instead impact the main thread...er, well, what I am thinking of as the main thread (not the callback).
> 
> Any ideas? Thanks,
> Kevin
> ------------------------------------------------------------------------------
> _______________________________________________
> ctypes-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/ctypes-users

------------------------------------------------------------------------------

_______________________________________________
ctypes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ctypes-users
signature.asc (application/pgp-signature, 496 B)
-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - https://gpgtools.org

iQEcBAEBCgAGBQJXwwNAAAoJEMgWrvcLlYXnEjYH/isvhEM8MgSx6lzzsxFLB4Cf
NZfxeFNCHMLFreSXmgw7BASrsDT04Y8kJUhN5cxXpiYrEC6jYOhwFSNQ/fbw1hJ4
+eKVy5Mdj+pFRfs5suGOZo0OSnN7RnJSj95x8QytWTJDOeODs/vTdjuVuV1k26iu
G5B5++Kmp7TIpG6Lf4xS3PbslCZ5d81/PPPKo9sqWNv1PdZGqdudKIQNSlwZWdnh
IkEwX6XJ6aX+rZzNWOHqQtseAU7+bucbOMHqwDCveb8XVo3wHZ8HN5DddAu8qju9
tUuAuNxNTjBuL/dnsD5H4ehhoki/NaVJTHJz32U1Xi90itUhyxw1b4Yhnn8299Y=
=s2wW
-----END PGP SIGNATURE-----