Re: threads in python

2020-08-28 Thread AudioGames . net Forum — Developers room : cartertemm via Audiogames-reflector


  


Re: threads in python

As far as I can tell this isn't so much an issue with the library as it is an issue with your code and knowledge of the way threading works.In the slim chance that someone is searching around and has the same question, I explained more in the issue he created.

URL: https://forum.audiogames.net/post/565311/#p565311




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: threads in python

2020-08-28 Thread AudioGames . net Forum — Developers room : cartertemm via Audiogames-reflector


  


Re: threads in python

This isn't an issue with threads

URL: https://forum.audiogames.net/post/565309/#p565309




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: threads in python

2020-08-26 Thread AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector


  


Re: threads in python

@5, ah, I stand corrected then.

URL: https://forum.audiogames.net/post/564839/#p564839




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: threads in python

2020-08-26 Thread AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector


  


Re: threads in python

@2that's incorrect. For what they're trying to do, threading will work.  The non-newbie answer to this is that there's a mutex plus a timeout around the bytecode interpreter loop, but this means that anything doing I/O and anything doing calls into C won't block it, and even if you're doing a bunch of Python threads they are actually OS threads that do actually schedule, and they don't all get blocked or anything like that, you're just limited to single-core compute performance.  So i.e. socket.read() will happily run in parallel and reacquire the GIL when data arrives.  Cython lets you get around it some but only if you're explicit about releasing the GIL, as really Cython is a way to write Python C extensions without using C, not a thing for binding C libraries.   I think CFFI knows how to always release it when calling into C by default.The newbie answer, for everyone who reads the above paragraph, is that it doesn't matter for games because in practice a game can't rely on more than one core anyway.  I don't remember the Python threading API offhand but the above looks broadly right; I'm guessing it's something to do with whatever the library is.  In general, if the library isn't threading-aware and you try to use it with threads without some form of lock or other synchronization, it'll crash or do weird things.  That's true of any programming language, and what I suspect may be happening here, though if you want to verify if the therad is running, write a function that prints.  The Python-specific threading details can be ignored until you decide you want to do something like pathfinding in background threads, but since trying to do that sort of thing is a terrible idea for a whole host of other reasons, it probably won't ever come up.

URL: https://forum.audiogames.net/post/564796/#p564796




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: threads in python

2020-08-26 Thread AudioGames . net Forum — Developers room : ivan_soto via Audiogames-reflector


  


Re: threads in python

You should use callbacks for the tt api that Carter wrote

URL: https://forum.audiogames.net/post/564776/#p564776




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: threads in python

2020-08-26 Thread AudioGames . net Forum — Developers room : pauliyobo via Audiogames-reflector


  


Re: threads in python

I wonder if using something like asyncio in your case would help, since what you're after is simply the function not blocking as far as I understand.

URL: https://forum.audiogames.net/post/564773/#p564773




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: threads in python

2020-08-26 Thread AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector


  


Re: threads in python

To my knowledge, threading in Python just doesn't work without cythonizing your code first. You can thank the GIL for that -- there's no way to get maximum performance out of Python without dropping into C or being really clever.

URL: https://forum.audiogames.net/post/564751/#p564751




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


threads in python

2020-08-26 Thread AudioGames . net Forum — Developers room : Simter via Audiogames-reflector


  


threads in python

Hi.I have created a multi porpose bot with carters team talk api. But i have 1 mayor problem. When i call bot.handle_messages() every thing i write afterwards doesn't execute. This seams to be because the methot blocks the rest of the code from executing. I have already tried a few multi treading methots like thr=threading.thread(target=sync_srv,args=()) and then thr.start() but the function still doesn't load. (for you interested, sync_srv is a function that is soposed to make it so you can make moderation on multiple servers at once, and this methot syncs these servers, and then you can pm the bot with stuff like /ban or /broadcast if you are in it's trusted list.) I also tried the old __threading module and the start_new_thread function but it just didn't start as well. Is there any thing else i can do?

URL: https://forum.audiogames.net/post/564669/#p564669




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: need help with using speech in threads in python

2020-03-09 Thread AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector


  


Re: need help with using speech in threads in python

Yeah. If it's I/O the GIL isn't out to murder you, and in general interacting with WX needs exactly this kind of thing anyway, so go for it. Had assumed that faster meant compute, because it usually does.That said I did think that accessible_output2 could handle threads.  I guess I was wrong. Perhaps I'll read the source at one point.

URL: https://forum.audiogames.net/post/507376/#p507376




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: need help with using speech in threads in python

2020-03-09 Thread AudioGames . net Forum — Developers room : jfayre via Audiogames-reflector


  


Re: need help with using speech in threads in python

Thanks so much! I actually did fix this by using a queue to pass speech messages to the main thread.As far as performance, I'm mainly using threads to avoid blocking the WX UI that I'm using. There is a series of functions that poll the flight simulator for instrument data. I put that function in it's own thread.It's essentially just a loop that runs constantly and puts messages in the queue  when things change. The project is at:http://www.github.com/jfayre/talking-flight-monitorAll the new code for the UI is in the dev branch. The master branch hasn't been updated with the UI yet.

URL: https://forum.audiogames.net/post/507371/#p507371




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: need help with using speech in threads in python

2020-03-08 Thread AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector


  


Re: need help with using speech in threads in python

My guess is that the issue is that you aren't inside a COM apartment, which is hard to fix. You may be able to use speech from only one thread and get it to initialize a COM apartment over there, or it might be an issue in comtypes.  But I wouldn't try to fix it directly.  If you dig around in accessible_output you might be able to find some magic initialization functions.  Then again you might not.  It's also possible calling say from the main thread first will make this work out.Now before I go further, I'm assuming you know about the GIL and that this means that pure python code on multiple threads isn't going to let you go faster because in actuality they're all just taking turns due to the GIL, and that you've decided on a way to deal with this like numpy or the multiprocessing module or something.  If you're I/O bound the I/O functions will release the GIL and this may work out for you, but otherwise the discussion we should be having isn't about accessible_output2 but rather how to make this go faster in the first place.  In all honesty unless you're I/O bound it's quite possibly worth that discussion anyway.But assuming you're good with all of that and there's not a simpler fix, the trick is to post function calls to the main thread.  There's two ways of doing this.  First is to find out if whatever UI thing you're using offers this functionality (most do).  If that doesn't help you, or if you're running your own loop, Python has a queue module which is threadsafe and supports a non-blocking get, so you can just make one of those, throw lambdas on it, and call them from the main thread.  Like this (very, very untested):import queue

mt_queue = queue.Queue()

# from any thread:
def call(func, *args, **kwargs):
mt_queue.put(lambda: func(*args, **kwargs))

# from the main thread. Won't block.
def drain():
try:
while True:
# False means don't block. Otherwise this will wait for the queue to have items.
cmd = mt_queue.get(False)
cmd()
except queue.Empty:
return

# example
call(say_something, "foo")Some explanation: you can either read from queues in blocking mode or non-blocking mode.  In blocking mode, the queue blocks the current thread forever until there's an item.  In non-blocking mode, the queue throws queue.Empty if it's empty.  So to drain a queue you do an infinite loop and specifically catch that exception, and the queue throwing the exception will break out of the loop.  In call, we use a lambda to convert myfunc (which can be any function) and any other arguments passed to call into a function taking zero arguments, which we then stick on the queue for later invocation from the main thread.You can use this to make anything happen from any thread, if you just change call and drain to take a queue as an argument.  Speech won't be the only thing like this.  If you want to i.e. have priority (more important messages, for instance) there's a priority queue in the queue module as well.  The latency is pretty good as long as whatever thread is receiving the calls is calling drain all the time.

URL: https://forum.audiogames.net/post/507104/#p507104




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


need help with using speech in threads in python

2020-03-08 Thread AudioGames . net Forum — Developers room : jfayre via Audiogames-reflector


  


need help with using speech in threads in python

Hi,In the Talking Flight Monitor software I'm writing, I want to be able to use threads to speed up the system.Unfortunately, it looks like the accessible_output_2 module doesn't support threading. Whenever I try to output anything using speech in the secondary thread,, I get a traceback like the following. This traceback was when I was testing with pypubsub, but it happens if I use the speech call directly in the second thread as well.Any ideas?Exception in thread Thread-1:                                                                                                                                                                                                                Traceback (most recent call last):                                                                                                                                                                                                             File "C:\python37\lib\site-packages\accessible_output2\outputs\http://sapi5.py", line 37, in __init__                                                                                                                                                 self.object = load_com("SAPI.SPVoice")                                                                                                                                                                                                     File "C:\python37\lib\site-packages\libloader-0.21-py3.7.egg\libloader\http://com.py", line 21, in load_com                                                                                                                                           raise com_error("Unable to load any of the provided com objects.")                                                                                                                                                                       http://pywintypes.com: Unable to load any of the provided com objects.                                                                                                                                                                        blankDuring handling of the above exception, another exception occurred:                                                                                                                                                                          blankTraceback (most recent call last):                                                                                                                                                                                                             File "C:\python37\lib\http://threading.py", line 917, in _bootstrap_inner                                                                                                                                                                             http://self.run()                                                                                                                                                                                                                                 File "C:\Users\jfayr\projects\talking-flight-monitor\http://flightsim.py", line 176, in run                                                                                                                                                           http://self.read()                                                                                                                                                                                                                         File "C:\Users\jfayr\projects\talking-flight-monitor\http://flightsim.py", line 355, in read_config                                                                                                                                                   pub.sendMessage("speak", arg1="test message")                                                                                                                                                                                              File "C:\python37\lib\site-packages\pubsub\core\http://publisher.py", line 216, in sendMessage                                                                                                                                                        topicObj.publish(**msgData)                                                                                                                                                                                                                File "C:\python37\lib\site-packages\pubsub\core\http://topicobj.py", line 452, in publish