1 /* OS/2 PM main program - creates a hidden window, and starts Python
2 * interpreter in a separate thread, so that Python scripts can be
3 * run in PM process space without a console Window. The interpreter
4 * is incorporated by linking in the Python DLL.
6 * As it stands, I don't think this is adequate for supporting Python
7 * GUI modules, as the Python thread doesn't have its own message
8 * queue - which is required of threads that want to create/use
11 * This code owes a lot to "OS/2 Presentation Manager Programming", by
14 * Andrew MacIntyre <andymac@bullseye.apana.org.au>, August 2001.
15 * Released under the terms of the Python 2.1.1 licence - see the LICENCE
16 * file in the Python v2.1.1 (or later) source distribution.
17 * Copyright assigned to the Python Software Foundation, 2001.
27 /* use structure to pass command line to Python thread */
36 /* make this a global to simplify access.
37 * it should only be set from the Python thread, or by the code that
38 * initiates the Python thread when the thread cannot be created.
42 extern DL_EXPORT(int) Py_Main(int, char **);
43 void PythonThread(void *);
46 main(int argc, char **argv)
48 ULONG FrameFlags = FCF_TITLEBAR |
61 /* init PM and create message queue */
62 hab = WinInitialize(0);
63 hmq = WinCreateMsgQueue(hab, 0);
65 /* create a (hidden) Window to house the window procedure */
66 args.Frame = WinCreateStdWindow(HWND_DESKTOP,
76 /* run Python interpreter in a thread */
80 if (-1 == (python_tid = _beginthread(PythonThread, NULL, 1024 * 1024, &args)))
82 /* couldn't start thread */
83 WinAlarm(HWND_DESKTOP, WA_ERROR);
88 /* process PM messages, until Python exits */
89 while (WinGetMsg(hab, &qmsg, NULLHANDLE, 0, 0))
90 WinDispatchMsg(hab, &qmsg);
92 DosKillThread(python_tid);
95 /* destroy window, shutdown message queue and PM */
96 WinDestroyWindow(args.Frame);
97 WinDestroyMsgQueue(hmq);
103 void PythonThread(void *argl)
108 /* PM initialisation */
109 hab = WinInitialize(0);
112 args = (arglist *)argl;
114 PythonRC = Py_Main(args->argc, args->argv);
116 /* enter a critical section and send the termination message */
119 WinPostMsg(args->Frame, WM_QUIT, NULL, NULL);
121 /* shutdown PM and terminate thread */