2

I know there have been many questions answered on this topic, but none of them worked. Using apache2.2, mod_wsgi 3.3, python 2.7.3 and django 1.4 on centos6.2.

I tried starting up my code form urls.py, it is executed random amount of times and is executed randomly after startup is already finished. Next I tried using middleware trick explained here Where to put Django startup code? Startup code was also executed random amount of times (printing out some debug messages, seeing same message multiple times).

The problem is, I wish to have one global TCP Client, connecting and communicating with TCP Server. It should be Initialized only once, if it randomly creates new instance old connection will be lost, destroyed who knows when and that socket will probably be destroyed when os runs out of memory (not sure about that). So the goal would be to have one global TCP Client, being used by all functions that trigger TCP Client functions such as Connect/Disconnect/Send/Receive.

Is there some kind of apache or mod_wsgi option for that? I am running same configuration on Windows 7 and everything works without a problem.

krizajb
  • 1,715
  • 3
  • 30
  • 43

1 Answers1

1

Had to modify apache httpd.conf with following lines: WSGIDaemonProcess site-1 threads=15

WSGIProcessGroup site-1

Basicly django was running in multiple processes and threads. To make global TCP Client thread safe, lock object threading.Lock() was helpful. Also created TcpClient as singleton, just in case.

krizajb
  • 1,715
  • 3
  • 30
  • 43