Container of gobjs.
GAplic supplies the main loop in a thread o subprocess context.
GAplic has the next methods:
A gaplic can run in a thread or subprocess context, always with the same interface.
To run a GAplic instance like a thread: setup_gaplic_thread().
To run a GAplic instance like a subprocess: setup_gaplic_process().
To use configuration file .ini with PasteDeploy in composite mode: gaplic_factory().
Container of gobj’s running under the same process or thread.
Parameters: |
|
---|
GAplic is the main boss. Manage the timer’s, event queues, etc. Supplies register, deregister and search or named-events.
Name | Type | Default value | Description |
---|---|---|---|
ini_settings | dict | {} | The ini settings will be set to all new created gobj by overwrite_parameters() function |
all_unique_names | bool | False | All named-gobjs are unique-named gobjs |
roles | tuple | () | Roles of gaplic |
trace_mach | bool | False | Display simple machine activity |
logger | None | None | |
router_enabled | bool | False | True if a (NOT Pyramid) router is enabled. |
Example:
from ginsfsm.gaplic import GAplic
if __name__ == "__main__":
ga = GAplic(name='Example1', roles='')
ga.create_gobj('test_aplic', GPrincipal, None)
try:
ga.start()
except KeyboardInterrupt:
print('Program stopped')
Factory function to create gobj’s instances.
Subclass of ginsfsm.gobj.GObj.create_gobj() to do something else, like to let unique-named-gobj instances.
Parameters: |
|
---|---|
Return type: | new gobj instance. |
When a gobj is created by the factory function, it’s added to their parent child list ginsfsm.gobj.GObj.dl_childs, and several attributes are created:
If the gclass is subclass of ginsfsm.c_sock.GSock two private attributes are added to the created gobj:
It’s the base of the asynchronous behavior.
Find a unique-named-gobj.
Send an event to an external gaplic.
Parameters: |
|
---|
Subscribe an event of an external gaplic by name.
Subscribe an event of an external gaplic by name.
Running as thread:
ga = GAplic()
worker = setup_gaplic_thread(ga)
worker.start()
Run gaplic as thread. Return the worker. You must call worker.start() to run the thread.
Running as subprocess:
ga = GAplic()
worker = setup_gaplic_process(ga)
worker.start()
Run gaplic as process. Return the worker. You must call worker.start() to run the subprocess.
Class derived from multiprocessing.Process to run gaplic in subprocess environment.
Runnig several threads or subprocesses:
from ginsfsm.gaplic import GAplic, setup_gaplic_thread
# run one gaplic as thread
ga_srv = GAplic(name='Server', roles='')
srv_worker = setup_gaplic_thread(ga_srv)
srv_worker.start()
ga_cli = GAplic(name='Client', roles='')
try:
# run the main gaplic as main process
ga_cli.start()
except (KeyboardInterrupt, SystemExit):
# stop the main gaplic
ga_srv.stop()
# wait to finish the other gaplic
srv_worker.join()
print('Program stopped')
You can configure and run your gaplic applications with PasteDeploy.
Available are the gcreate and gserve commands, similar to pcreate and pserve of Pyramid.
To use with PasteDeploy in composite.
Items of composite section:
main: name of a section that must return a gaplic instance. It will be the principal gaplic. threads: name of sections that must return gaplic instances. They will run in threads. subprocesses: name of sections that must return gaplic instances. They will run in subprocesses. wsgi: name of sections that must return a app paste factory. Wsgi applications are saved as global apps (set_global_app()). Example:
[composite:main] use = call:ginsfsm.gaplic:gaplic_factory main = wsgi-server wsgi = wsgi-application [app:wsgi-server] use = call:ginsfsm.examples.wsgi.simple_wsgi_server:main host = 0.0.0.0 port = 8000 application = wsgi-application GSock.trace_dump = true GObj.trace_mach = true [app:wsgi-application] use=call:ginsfsm.examples.wsgi.simple_wsgi_server:paste_app_factory
The prototype for wsgi (paste app factory) is:
def paste_app_factory(global_conf, **local_conf):
return wsgi-application
The prototype for main, threads and subprocesses is:
def main(global_conf, **local_config):
return gaplic-instance